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;
//ideja je da nadjemo rastojanje
//svakog cvora od pocetnih
//i da onda vidimo koji im je lower_bound
//u nizu prefiksnih suma k,3k,6k...
//treba da se testira
int n,m,q;
ll k;
vector<int> adj[100005];
queue<int> qq;
ll dist[100005];
vector<ll> s;
void rasiri()
{
while(!qq.empty())
{
int cv = qq.front();
qq.pop();
for(int x : adj[cv])
{
if(dist[x]==-1)
{
dist[x] = dist[cv]+1;
qq.push(x);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
cin >> n >> m >> q >> k;
for(int i=1;i<=n;i++)
dist[i] = -1;
for(ll i = k;i<=n;i+=k)
{
if(i==k) s.push_back(k);
else
{
s.push_back(s.back() + i);
}
}
for(int i=1;i<=q;i++)
{
int x;
cin >> x;
qq.push(x);
dist[x] = 0;
}
for(int i=1;i<=m;i++)
{
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
rasiri();
for(int i=1;i<=n;i++)
{
if(dist[i]==0)
{
cout << 0 << " ";
continue;
}
vector<ll>::iterator it;
it = lower_bound(s.begin(),s.end(),dist[i]);
int dani = it-s.begin()+1;
cout << dani << " ";
}
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... |