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 pb push_back
using namespace std;
constexpr static int MXN = 1e5;
int n, m, k, q;
bitset<MXN> visited;
vector<int> g[MXN];
vector<int> v;
int res[MXN];
void dfs(int node, int s, int c)
{
visited[node] = true;
if (c != s*k)
res[node] = s;
if (c == 0)
{
v.pb(node);
return;
}
for (int cc : g[node])
{
if (!visited[cc])
dfs(cc, s, c-1);
}
}
int main()
{
cin >> n >> m >> q >> k;
for (int i = 0; i < q; i++)
{
int val;
cin >> val;
v.pb(val-1);
}
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--,b--;
g[a].pb(b);
g[b].pb(a);
}
int j = 1;
while (v.size())
{
vector<int> t = v;
v.clear();
for (int i : t)
visited[i] = true;
for (int i : t)
dfs(i, j, j*k);
j++;
}
for (int i = 0; i < n; i++)
cout << res[i] << " ";
cout << "\n";
}
# | 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... |