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'
#define MAXN 100003
using namespace std;
int n, m, t, k;
vector <int> adj[MAXN];
int dist[MAXN];
queue <int> q;
void input()
{
cin >> n >> m >> t >> k;
for (int i = 0; i <= n; ++i)
dist[i] = -1;
for (int i = 0; i < t; ++i)
{
int x;
cin >> x;
dist[x] = 0;
q.push(x);
}
for (int i = 0; i < m; ++i)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
}
void bfs()
{
while (!q.empty())
{
int tmp = q.front();
q.pop();
for (auto nb: adj[tmp])
{
if (dist[nb] == -1 || dist[nb] > dist[tmp] + 1)
{
dist[nb] = dist[tmp] + 1;
q.push(nb);
}
}
}
}
int get_ans(int x)
{
if (x == 0)
return 0;
if (x <= k)
return 1;
int d = k;
for (int i = 2; ; ++i)
{
d += i * k;
if (d >= x)
return i;
}
}
void solve()
{
bfs();
cout << get_ans(dist[1]);
for (int i = 2; i <= n; ++i)
{
cout << " " << get_ans(dist[i]);// << dist[i] << endl;
}
cout << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
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... |