#include<bits/stdc++.h>
using namespace std;
int const maxn = 100005;
int n,m,q,k;
int a[maxn];
vector<int>v[maxn];
void read()
{
int i;
cin>>n>>m>>q>>k;
for(i=0;i<q;i++)
cin>>a[i];
int x,y;
for(i=0;i<m;i++)
{
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
}
int ans[maxn];
queue<int>gq;
bool used[maxn];
void dfs(int i, int d, int p)
{
if(d == 0)return ;
int j,sz=v[i].size();
for(j=0;j<sz;j++)
{
int nb = v[i][j];
if(!used[nb])
{
gq.push(nb);
ans[nb] = ans[p]+1;
dfs(nb,d-1,p);
}
}
}
void bfs_solve()
{
int i;
for(i=0;i<q;i++)
{
gq.push(a[i]);
ans[a[i]] = 1;
used[a[i]]=true;
}
while(!gq.empty())
{
int t = gq.front();
gq.pop();
dfs(t,k*ans[t],t);
used[t]=true;
}
}
void print()
{
int i;
for(i=1;i<=n;i++)
cout<<ans[i]-1<<" ";
cout<<endl;
}
int main()
{
read();
bfs_solve();
print();
return 0;
}
/*
6 5 1
1
1 2
2 3
3 5
5 4
4 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1108 ms |
377472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1114 ms |
381496 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1118 ms |
393616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1118 ms |
399184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1124 ms |
403160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1100 ms |
462720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1116 ms |
404448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1111 ms |
202340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1109 ms |
183516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1113 ms |
223236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1103 ms |
222704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1107 ms |
190804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1107 ms |
210428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1105 ms |
209896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |