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>
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;
}
# | 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... |