# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
733474 | vjudge1 | Birmingham (COCI20_birmingham) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author: MisterReaper (Ahmet Alp Orakci)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 5;
#ifndef ONLINE_JUDGE
#include "debug.h"
#define OPEN freopen(".in", "r", stdin); freopen(".out", "w", stdout);
#define TIME cerr << "\n" << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds ";
#else
#define debug(...) void(23)
#define OPEN void(0000)
#define TIME void(232323233)
#endif
vector <int> graph[MAXN];
int ans[MAXN];
void solve()
{
memset(ans, -1, sizeof(ans));
int n, m, q, k; cin >> n >> m >> q >> k;
int arr[q];
for(int &i : arr) cin >> i;
vector <int> vec;
vec.emplace_back(0);
for(int i = 1; vec.back() <= n; i++) vec.emplace_back(vec.back() + k * i);
for(int i = 1; i <= m; i++)
{
int u, v; cin >> u >> v;
graph[u].emplace_back(v);
graph[v].emplace_back(u);
}
queue <pair <int, int>> que;
for(int i : arr) que.emplace(i, 0);
while(!que.empty())
{
auto [node, cost] = que.front();
que.pop();
if(ans[node] != -1) continue;
ans[node] = cost;
for(int child : graph[node])
{
que.emplace(child, cost +1);
}
}
for(int i = 1; i <= n; i++)
{
debug(ans[i]);
int ret = upper_bound(vec.begin(), vec.end(), ans[i] -1) - vec.begin();
cout << ret << " ";
}
return;
}
int32_t main()
{
OPEN;
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
while(t--)
{
solve();
}
TIME;
return 0;
}