#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define all(c) (c).begin(), (c).end()
const int N = 1e5 + 5;
vector<int> adj[N],vis(N),ans(N);
void solve(){
int n,m,q,k;
cin >> n >> m >> q >> k;
queue<array<int,3>> qq;
for(int i = 0; i < q; i++){
int x; cin >> x;
qq.push({x,0,1});
vis[x] = 1; ans[x] = -1;
}
for(int i = 0; i < m; i++){
int a,b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
while(qq.size()){
auto[node,d,x] = qq.front(); qq.pop();
if(ans[node] != -1) ans[node] = x;
for(int go : adj[node]){
if(vis[go]) continue;
if(1 + d > k * x) x++,d = 0;
vis[go] = 1;
qq.push({go,1 + d,x});
}
}
for(int i = 1; i <= n; i++){
cout << ans[i] + (ans[i] == - 1) << ' ';
}
}
signed main(){
#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
1 ms |
4184 KB |
Output is correct |
3 |
Correct |
1 ms |
4188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4276 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4184 KB |
Output is correct |
2 |
Correct |
1 ms |
4184 KB |
Output is correct |
3 |
Correct |
1 ms |
4184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4184 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4184 KB |
Output is correct |
4 |
Correct |
2 ms |
4400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4184 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4184 KB |
Output is correct |
4 |
Correct |
1 ms |
4184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4184 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4184 KB |
Output is correct |
4 |
Correct |
1 ms |
4184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
11096 KB |
Output is correct |
2 |
Correct |
52 ms |
11796 KB |
Output is correct |
3 |
Correct |
55 ms |
12116 KB |
Output is correct |
4 |
Correct |
42 ms |
10580 KB |
Output is correct |
5 |
Correct |
48 ms |
10904 KB |
Output is correct |
6 |
Correct |
55 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
11848 KB |
Output is correct |
2 |
Correct |
53 ms |
11604 KB |
Output is correct |
3 |
Correct |
53 ms |
11636 KB |
Output is correct |
4 |
Correct |
53 ms |
11856 KB |
Output is correct |
5 |
Correct |
52 ms |
11600 KB |
Output is correct |
6 |
Correct |
48 ms |
11600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
11344 KB |
Output is correct |
2 |
Correct |
55 ms |
11844 KB |
Output is correct |
3 |
Correct |
60 ms |
12128 KB |
Output is correct |
4 |
Correct |
56 ms |
11844 KB |
Output is correct |
5 |
Correct |
48 ms |
11084 KB |
Output is correct |
6 |
Correct |
49 ms |
11608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
10832 KB |
Output is correct |
2 |
Correct |
55 ms |
11344 KB |
Output is correct |
3 |
Correct |
66 ms |
11676 KB |
Output is correct |
4 |
Correct |
48 ms |
11088 KB |
Output is correct |
5 |
Correct |
44 ms |
10832 KB |
Output is correct |
6 |
Correct |
51 ms |
11628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
10832 KB |
Output is correct |
2 |
Correct |
49 ms |
11088 KB |
Output is correct |
3 |
Correct |
48 ms |
10952 KB |
Output is correct |
4 |
Correct |
48 ms |
11088 KB |
Output is correct |
5 |
Correct |
48 ms |
11172 KB |
Output is correct |
6 |
Correct |
44 ms |
11344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
10832 KB |
Output is correct |
2 |
Correct |
53 ms |
11348 KB |
Output is correct |
3 |
Correct |
48 ms |
11092 KB |
Output is correct |
4 |
Correct |
55 ms |
11360 KB |
Output is correct |
5 |
Correct |
63 ms |
10980 KB |
Output is correct |
6 |
Correct |
49 ms |
11600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
11028 KB |
Output is correct |
2 |
Correct |
43 ms |
10576 KB |
Output is correct |
3 |
Correct |
57 ms |
11988 KB |
Output is correct |
4 |
Correct |
46 ms |
11224 KB |
Output is correct |
5 |
Correct |
54 ms |
11188 KB |
Output is correct |
6 |
Correct |
60 ms |
12432 KB |
Output is correct |