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 fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
void print(){
cout<<"\n";
}
template<class te,class ...ti>
void print(const te&v, const ti&...nv) {
cout<<v;
if(sizeof...(nv)){
cout<<" ";
print(nv...);
}
}
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
const int inf=1e9;
void slv(){
int n,m,q,k;
cin>>n>>m>>q>>k;
vi rbe(n,0);
rep(_,q){
int x;
cin>>x;
x--;
rbe[x]=1;
}
vec(vi) adj(n);
rep(i,m){
int u,v;
cin>>u>>v;
u--,v--;
adj[u].pb(v);
adj[v].pb(u);
}
priority_queue<pii,vec(pii),greater<pii>> pq;
vi dp(n,inf);
rep(v,n){
if(rbe[v]){
pq.push({0,v});
dp[v]=0;
}
}
while(sz(pq)){
pii top=pq.top();
pq.pop();
int v=top.se,cost=top.fi;
if(dp[v]!=cost) continue;
for(auto u : adj[v]){
if(dp[u]>cost+1){
dp[u]=cost+1;
pq.push({cost+1,u});
}
}
}
rep(v,n){
ll ans=sqrt((dp[v]*2)/k);
while(ans*(ans+1)*(ll)k<2ll*(ll)dp[v]) ans++;
while((ans-1)*ans*(ll)k>=2ll*(ll)dp[v]) ans--;
print(max(0ll,ans),"");
}
print('\n');
}
int main(){
_3qplfh5;
int t=1;
// cin>>t;
rep(cs,t)
slv();
//
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... |