#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, Q, K;
cin >> N >> M >> Q >> K;
vector<int> s(Q);
for (int i = 0;i < Q; ++i) {
cin >> s[i];
s[i] -= 1;
}
vector<vector<int>> g(N);
for (int i = 0;i < M; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
queue<array<int, 2>> q;
for (int i = 0;i < Q; ++i) {
q.push({0, s[i]});
}
vector<int> dist(N, -1);
while (q.size()) {
auto [d, u] = q.front();
q.pop();
if (dist[u] != -1) {
continue;
}
dist[u] = d;
for (int v : g[u]) {
q.push({d+1, v});
}
}
vector<int> idx(N), ans(N);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int i, int j) { return dist[i] < dist[j]; });
int64_t day = 0, can = 0;
for (int i = 0;i < N; ++i) {
int j = idx[i];
while (can < dist[j]) {
day += 1;
can += K * day;
}
ans[j] = day;
}
for (int i = 0;i < N; ++i) {
cout << ans[i] << ' ';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
8724 KB |
Output is correct |
2 |
Correct |
125 ms |
8956 KB |
Output is correct |
3 |
Correct |
125 ms |
10024 KB |
Output is correct |
4 |
Correct |
95 ms |
8532 KB |
Output is correct |
5 |
Correct |
107 ms |
8452 KB |
Output is correct |
6 |
Correct |
125 ms |
9732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
9172 KB |
Output is correct |
2 |
Correct |
114 ms |
9516 KB |
Output is correct |
3 |
Correct |
140 ms |
9700 KB |
Output is correct |
4 |
Correct |
127 ms |
9452 KB |
Output is correct |
5 |
Correct |
125 ms |
9044 KB |
Output is correct |
6 |
Correct |
113 ms |
9212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
9112 KB |
Output is correct |
2 |
Correct |
124 ms |
9340 KB |
Output is correct |
3 |
Correct |
124 ms |
9548 KB |
Output is correct |
4 |
Correct |
117 ms |
9140 KB |
Output is correct |
5 |
Correct |
110 ms |
8504 KB |
Output is correct |
6 |
Correct |
109 ms |
9044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
8788 KB |
Output is correct |
2 |
Correct |
112 ms |
9076 KB |
Output is correct |
3 |
Correct |
125 ms |
9736 KB |
Output is correct |
4 |
Correct |
106 ms |
9032 KB |
Output is correct |
5 |
Correct |
100 ms |
8868 KB |
Output is correct |
6 |
Correct |
115 ms |
9040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
8736 KB |
Output is correct |
2 |
Correct |
107 ms |
9044 KB |
Output is correct |
3 |
Correct |
114 ms |
9128 KB |
Output is correct |
4 |
Correct |
104 ms |
8980 KB |
Output is correct |
5 |
Correct |
105 ms |
8684 KB |
Output is correct |
6 |
Correct |
125 ms |
9004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
8724 KB |
Output is correct |
2 |
Correct |
112 ms |
9180 KB |
Output is correct |
3 |
Correct |
114 ms |
8912 KB |
Output is correct |
4 |
Correct |
114 ms |
9116 KB |
Output is correct |
5 |
Correct |
103 ms |
8996 KB |
Output is correct |
6 |
Correct |
112 ms |
9416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
8980 KB |
Output is correct |
2 |
Correct |
99 ms |
8788 KB |
Output is correct |
3 |
Correct |
124 ms |
9540 KB |
Output is correct |
4 |
Correct |
105 ms |
8680 KB |
Output is correct |
5 |
Correct |
120 ms |
9028 KB |
Output is correct |
6 |
Correct |
123 ms |
9812 KB |
Output is correct |