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>
#define int long long
#define pb push_back
#define endl '\n'
using namespace std;
const int N = 1e5 + 5;
int n,m,p,k,dist[N];
vector<int> g[N];
queue<int> q;
void bfs(){
while(!q.empty()){
int x=q.front(); q.pop();
for(auto go: g[x]){
if(dist[x]+1<dist[go]){
dist[go]=dist[x]+1;
q.push(go);
//cout<<go<<" from "<<x<<" with "<<dist[go]<<endl;
}
}
}
}
int bs(int x){
int l=0, r=1e9, ans=-1;
while(l<=r){
int m=l+(r-l)/2;
if(m*(m+1)*k/2 >= x ){
ans=m;
r=m-1;
}
else
l=m+1;
}
return ans;
}
void solve(){
cin>>n>>m>>p>>k;
for(int i=0;i<=n;i++) dist[i]=1e12;
for(int i=0;i<p;i++){
int x; cin>>x;
dist[x]=true;
q.push(x);
}
for(int i=0;i<m;i++){
int a,b; cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
bfs();
for(int i=1;i<=n;i++){
int ans=0;
int omg=k;
while(dist[i]>omg){
ans++;
omg+=ans*k;
}
cout<<ans<<" ";
}
}
int32_t main(){
cin.tie(0)->sync_with_stdio(false);
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... |