This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |