# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238617 | SamAnd | Birmingham (COCI20_birmingham) | C++17 | 153 ms | 10748 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.
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;
int n, m, q, k;
vector<int> g[N];
int ans[N];
bool c[N];
int dist[N];
void solv()
{
scanf("%d%d%d%d", &n, &m, &q, &k);
for (int i = 1; i <= n; ++i)
ans[i] = -1;
while (q--)
{
int x;
scanf("%d", &x);
ans[x] = 0;
}
while (m--)
{
int x, y;
scanf("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
for (int d = 1; ; ++d)
{
bool z = true;
for (int i = 1; i <= n; ++i)
{
if (ans[i] == -1)
{
z = false;
break;
}
}
if (z)
break;
queue<int> q;
for (int i = 1; i <= n; ++i)
{
c[i] = false;
if (ans[i] != -1)
{
c[i] = true;
dist[i] = 0;
q.push(i);
}
}
while (!q.empty())
{
int x = q.front();
q.pop();
if (dist[x] > d * k)
continue;
if (ans[x] == -1)
ans[x] = d;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (!c[h])
{
c[h] = true;
dist[h] = dist[x] + 1;
q.push(h);
}
}
}
}
for (int i = 1; i <= n; ++i)
printf("%d ", ans[i]);
printf("\n");
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
//ios_base::sync_with_stdio(false), cin.tie(0);
solv();
return 0;
}
//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}
Compilation message (stderr)
# | 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... |