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>
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
int n,m,k,dis[100005],root[1000005];
vector<int> adj[100005];
string x;
bool vis[100005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(".INP","r",stdin);
// freopen(".OUT","w",stdout);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
dis[i]=1e9;
}
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
cin>>x;
for(int i=1;i<=k;i++) cin>>root[i];
priority_queue<pair<int,int>> q;
q.push({0,root[1]});
dis[root[1]]=0;
while(!q.empty())
{
int a=q.top().se;q.pop();
if(vis[a]) continue;
vis[a]=true;
for(auto b:adj[a])
{
if(dis[b]>dis[a]+1)
{
dis[b]=dis[a]+1;
q.push({-dis[b],b});
}
}
}
for(int i=1;i<=n;i++)
{
cout<<dis[i]<<"\n";
}
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... |