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;
typedef long long ll;
#define pb push_back
#define st first
#define nd second
#define MOD 1000000007
typedef pair<ll, ll> pii;
typedef pair<pii, ll> piiq;
const ll maxn = 2e5 + 5;
ll n, m, qu, k, vis[maxn], ans[maxn];
vector<ll> v[maxn];
int main(){
cin >> n >> m >> qu >> k;
memset(ans, -1, sizeof(ans));
queue<piiq> q;
for (int i = 0; i < qu; i++)
{
ll a;
cin >> a;
q.push({{a, 0}, 1});
ans[a] = 0;
}
for (int i = 0; i < m; i++)
{
ll y, u;
cin >> y >> u;
v[y].pb(u);
v[u].pb(y);
}
while(!q.empty()){
piiq curr = q.front();
ll index = curr.st.st, dis = curr.st.nd, day = curr.nd;
q.pop();
if(vis[index]){
continue;;
}
vis[index] = 1;
if(dis > k){
dis = 0;
day++;
}
if(ans[index] == -1){
ans[index] = day;
}
for (int i = 0; i < v[index].size(); i++)
{
ll next = v[index][i];
q.push({{next, dis + 1}, day});
}
}
for (int i = 1; i <= n; i++)
{
cout << ans[i] << " ";
}
}
Compilation message (stderr)
birmingham.cpp: In function 'int main()':
birmingham.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < v[index].size(); 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... |