#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n, m, f, k;
vector <int> graph[MAXN];
queue <int> q;
int vis[MAXN];
int lvl[MAXN];
void read_input()
{
cin >> n >> m >> f >> k;
for(int i = 1; i <= n; i++)
{
vis[i] = -1;
lvl[i] = -1;
}
int h;
for(int i = 0; i < f; i++)
{
cin >> h;
q.push(h);
lvl[h] = 0;
vis[h] = 0;
}
int v, w;
for(int i = 0; i < m; i++)
{
cin >> v >> w;
graph[v].push_back(w);
graph[w].push_back(v);
}
}
void solve()
{
while(!q.empty())
{
int v = q.front(); q.pop();
//cout << v << "\n";
int new_l = lvl[v];
int ost = vis[v] - 1;
if(ost < 0)
{
new_l++;
ost = k * new_l;
ost--;
//cout << " " << v << " " << vis[v] << " " << new_l << " " << ost << "\n";
}
for(auto x : graph[v])
{
if(vis[x] == -1)
{
//cout << "DAS";
lvl[x] = new_l;
vis[x] = ost;
q.push(x);
}
}
}
for(int i = 1; i <= n; i++)
{
cout << lvl[i] << " ";
}
cout << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
read_input();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
7800 KB |
Output is correct |
2 |
Correct |
96 ms |
8056 KB |
Output is correct |
3 |
Correct |
100 ms |
8184 KB |
Output is correct |
4 |
Correct |
85 ms |
7544 KB |
Output is correct |
5 |
Correct |
105 ms |
7760 KB |
Output is correct |
6 |
Correct |
105 ms |
8184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
8056 KB |
Output is correct |
2 |
Correct |
102 ms |
8056 KB |
Output is correct |
3 |
Correct |
96 ms |
8056 KB |
Output is correct |
4 |
Correct |
108 ms |
8312 KB |
Output is correct |
5 |
Correct |
102 ms |
8056 KB |
Output is correct |
6 |
Correct |
86 ms |
7720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
7928 KB |
Output is correct |
2 |
Correct |
102 ms |
8188 KB |
Output is correct |
3 |
Correct |
100 ms |
8184 KB |
Output is correct |
4 |
Correct |
101 ms |
8184 KB |
Output is correct |
5 |
Correct |
95 ms |
7800 KB |
Output is correct |
6 |
Correct |
93 ms |
7804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
7804 KB |
Output is correct |
2 |
Correct |
97 ms |
8024 KB |
Output is correct |
3 |
Correct |
111 ms |
8056 KB |
Output is correct |
4 |
Correct |
102 ms |
7800 KB |
Output is correct |
5 |
Correct |
89 ms |
7672 KB |
Output is correct |
6 |
Correct |
119 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
7672 KB |
Output is correct |
2 |
Correct |
96 ms |
7928 KB |
Output is correct |
3 |
Correct |
89 ms |
7800 KB |
Output is correct |
4 |
Correct |
104 ms |
7804 KB |
Output is correct |
5 |
Correct |
90 ms |
7800 KB |
Output is correct |
6 |
Correct |
84 ms |
7672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
7700 KB |
Output is correct |
2 |
Correct |
103 ms |
8060 KB |
Output is correct |
3 |
Correct |
89 ms |
7672 KB |
Output is correct |
4 |
Correct |
112 ms |
8032 KB |
Output is correct |
5 |
Correct |
92 ms |
7800 KB |
Output is correct |
6 |
Correct |
95 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
7776 KB |
Output is correct |
2 |
Correct |
97 ms |
7672 KB |
Output is correct |
3 |
Correct |
107 ms |
8184 KB |
Output is correct |
4 |
Correct |
89 ms |
7800 KB |
Output is correct |
5 |
Correct |
90 ms |
7928 KB |
Output is correct |
6 |
Correct |
109 ms |
8184 KB |
Output is correct |