mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
parent
1aee9acbc9
commit
9638b38c39
49
S2OJ/184/184.cpp
Normal file
49
S2OJ/184/184.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user