This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
#define pb push_back
#define lim 300000
#define till 40001
// # of primes till 1e6 = 7e4
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
using pii = array<int,2>;
const int mod=1000000007ll;
void solve(){
int n,m,Q,k;
cin>>n>>m>>Q>>k;
queue<int>q;
int vis[n];
memset(vis,-1,sizeof(vis));
for(int i=0;i<Q;i++){
int tem;
cin>>tem;
tem--;
q.push(tem);
vis[tem]=0;
}
vector<int>v[n];
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
x--,y--;
v[x].pb(y);
v[y].pb(x);
}
//cerr<<v[2].size()<<"\n";
while(q.size()){
int top=q.front();
q.pop();
//cerr<<top<<" doing\n";
for(int i:v[top]){
if(vis[i]==-1){
//cerr<<i<<" "<<vis[i]<<" ";
vis[i]=vis[top]+1;
q.push(i);
}
}
}
vector<int>days;
days.pb(0);
int now=k;
for(int i=2;*days.rbegin()<n;i++){
days.pb(*days.rbegin()+now);
//cerr<<*days.rbegin()<<"\n";
now+=k;
}
//cerr<<"ok\n";
for(int i=0;i<n;i++){
//cerr<<vis[i]<<" "<<*days.rbegin()<<"\n";
cout<<lower_bound(days.begin(),days.end(),vis[i])-days.begin()<<" ";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
#ifndef INTERACTIVE
freopen("in","r",stdin);
#endif
freopen("out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | 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... |