#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
using arr = array<long long, 3>;
const int N = 50004;
const long long INF = (int) 1e15;
char c[N];
vector<int> g[N];
vector<vector<long long>> dijkstra(int n, int src) {
vector<vector<long long>> ret(3, vector<long long> (n + 1, INF));
ret[0][src] = 0;
priority_queue<arr, vector<arr>, greater<arr>> pq;
pq.push({0, 0, src});
while (!pq.empty()) {
auto [cost, st, v] = pq.top();
pq.pop();
if (cost != ret[st][v]) {
continue;
}
int nst = st + (c[v] == '1');
for (int u : g[v]) {
if (nst < 3 && cost + 1 < ret[nst][u]) {
ret[nst][u] = cost + 1;
pq.push({ret[nst][u], nst, u});
}
}
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= n; ++i) {
cin >> c[i];
}
vector<int> x(k);
for (int i = 0; i < k; ++i) {
cin >> x[i];
}
vector<vector<long long>> mn(2, vector<long long>(n + 1, INF));
vector<vector<long long>> dist1 = dijkstra(n, x[0]);
int cnt = count(c + 1, c + 1 + n, '1');
vector<vector<vector<long long>>> dist(cnt);
for (int i = 1, cur = 0; i <= n; ++i) {
if (c[i] == '1') {
dist[cur] = dijkstra(n, i);
for (int j = 1; j <= n; ++j) {
mn[0][j] = min(mn[0][j], dist[cur][1][j]);
mn[1][j] = min(mn[1][j], dist[cur][2][j]);
}
cur++;
}
}
vector<long long> s(2);
for (int i = 1; i < k; ++i) {
s[0] += mn[0][x[i]];
s[1] += mn[1][x[i]];
}
for (int i = 1; i <= n; ++i) {
long long ans = dist1[0][i];
ans = min(ans, dist1[1][i] + s[0]);
ans = min(ans, dist1[2][i] + s[1]);
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1884 KB |
Output is correct |
2 |
Correct |
11 ms |
4720 KB |
Output is correct |
3 |
Correct |
19 ms |
6768 KB |
Output is correct |
4 |
Correct |
14 ms |
6356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
27 ms |
5612 KB |
Output is correct |
3 |
Correct |
32 ms |
7884 KB |
Output is correct |
4 |
Correct |
29 ms |
7892 KB |
Output is correct |
5 |
Correct |
46 ms |
8200 KB |
Output is correct |
6 |
Correct |
45 ms |
7884 KB |
Output is correct |
7 |
Correct |
26 ms |
6688 KB |
Output is correct |
8 |
Correct |
25 ms |
7660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
33 ms |
6224 KB |
Output is correct |
3 |
Correct |
56 ms |
9072 KB |
Output is correct |
4 |
Correct |
34 ms |
9160 KB |
Output is correct |
5 |
Correct |
37 ms |
9676 KB |
Output is correct |
6 |
Correct |
56 ms |
8908 KB |
Output is correct |
7 |
Correct |
60 ms |
8908 KB |
Output is correct |
8 |
Correct |
32 ms |
9448 KB |
Output is correct |
9 |
Correct |
17 ms |
4228 KB |
Output is correct |
10 |
Correct |
19 ms |
4100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2140 KB |
Output is correct |
2 |
Incorrect |
27 ms |
24908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
511 ms |
52572 KB |
Output is correct |
2 |
Runtime error |
439 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
511 ms |
52572 KB |
Output is correct |
2 |
Runtime error |
439 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2140 KB |
Output is correct |
2 |
Incorrect |
27 ms |
24908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1884 KB |
Output is correct |
2 |
Correct |
11 ms |
4720 KB |
Output is correct |
3 |
Correct |
19 ms |
6768 KB |
Output is correct |
4 |
Correct |
14 ms |
6356 KB |
Output is correct |
5 |
Correct |
3 ms |
1884 KB |
Output is correct |
6 |
Correct |
27 ms |
5612 KB |
Output is correct |
7 |
Correct |
32 ms |
7884 KB |
Output is correct |
8 |
Correct |
29 ms |
7892 KB |
Output is correct |
9 |
Correct |
46 ms |
8200 KB |
Output is correct |
10 |
Correct |
45 ms |
7884 KB |
Output is correct |
11 |
Correct |
26 ms |
6688 KB |
Output is correct |
12 |
Correct |
25 ms |
7660 KB |
Output is correct |
13 |
Correct |
4 ms |
1884 KB |
Output is correct |
14 |
Correct |
33 ms |
6224 KB |
Output is correct |
15 |
Correct |
56 ms |
9072 KB |
Output is correct |
16 |
Correct |
34 ms |
9160 KB |
Output is correct |
17 |
Correct |
37 ms |
9676 KB |
Output is correct |
18 |
Correct |
56 ms |
8908 KB |
Output is correct |
19 |
Correct |
60 ms |
8908 KB |
Output is correct |
20 |
Correct |
32 ms |
9448 KB |
Output is correct |
21 |
Correct |
17 ms |
4228 KB |
Output is correct |
22 |
Correct |
19 ms |
4100 KB |
Output is correct |
23 |
Correct |
6 ms |
2140 KB |
Output is correct |
24 |
Incorrect |
27 ms |
24908 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |