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>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define sz(x) ll(x.size())
#define pb push_back
#define N 100005
#define M ll(998244353)
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
//typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set;
vector <int> g[N];
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, q, k;
cin >> n >> m >> q >> k;
vector <int> gr(q);
for (int i = 0; i < q; i++) cin >> gr[i];
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
int ans[n + 1], kol = q;
for (int i = 1; i <= n; i++) ans[i] = -1;
for (auto it : gr) ans[it] = 0;
int day = 1;
while (kol < n)
{
vector <int> vr; vr.clear();
for (int i = 0; i < day * k && kol < n; i++)
{
for (auto it : gr)
{
if (kol == n) break;
for (auto itr : g[it])
{
if (kol == n) break;
if (ans[itr] != -1) continue;
ans[itr] = day;
kol++;
vr.pb(itr);
}
}
gr = vr;
vr.clear();
}
day++;
}
for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}
# | 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... |