0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00
https://sjzezoj.com/submission/48512
This commit is contained in:
Baoshuo Ren 2022-02-10 01:32:08 +08:00
parent 1aee9acbc9
commit 9638b38c39
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

49
S2OJ/184/184.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
#define endl '\n'
int n, x, dist[105];
std::vector<std::pair<int, int>> g[105];
bool vis[105];
void spfa(int s) {
memset(dist, 0x3f, sizeof(dist));
std::queue<int> q;
q.push(s);
vis[s] = true;
dist[s] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (dist[v] > std::max(1, (dist[u] + w + 1) / 2)) {
dist[v] = std::max(1, (dist[u] + w + 1) / 2);
if (!vis[v]) {
q.push(v);
vis[v] = true;
}
}
}
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> x;
if (x) g[j].push_back(std::make_pair(i, -x));
}
}
spfa(n);
cout << dist[1] << endl;
return 0;
}