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 endl '\n'
using namespace std;
const int MAXN = (1 << 18);
vector < int > v[MAXN];
int n, m, q, k, d[MAXN], s[MAXN], used[MAXN];
void read()
{
cin >> n >> m >> q >> k;
for (int i = 1; i <= q; i ++)
cin >> s[i];
int a, b;
for (int i = 0; i < m; i ++)
{
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
}
void bfs()
{
queue < int > qt;
for (int i = 1; i <= q; i ++)
qt.push(s[i]), used[s[i]] = 1;
while(!qt.empty())
{
int cur = qt.front(), sz = v[cur].size();
qt.pop();
for (int i = 0; i < sz; i ++)
{
int next = v[cur][i];
if (!used[next])
{
used[next] = used[cur] + 1;
qt.push(next);
}
}
}
}
void fill_array()
{
int id = 1, step = 1;
while(id <= n)
{
int r = id + step * k - 1;
if (n < r)
r = n;
for (int i = id; i <= r; i ++)
d[i] = step;
id = r + 1;
step ++;
}
}
void solve()
{
read();
bfs();
fill_array();
for (int i = 1; i <= n; i ++)
{
int x = used[i] - 1;
cout << d[x] << " ";
}
cout << endl;
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}
/**
7 8 1 1
2
1 2
2 3
3 4
1 4
4 7
7 5
5 6
6 3
*/
# | 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... |