MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

HackerEarth_problems/Big P and Party/solution.cpp:19–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17vector<ll> adj[1001];
18int vis[1001];
19int main()
20{
21 ios_base::sync_with_stdio(false);
22 cin.tie(NULL);
23 int n,m;
24 cin>>n>>m;
25 int u,v;
26 for(int i=0;i<n;i++)
27 {
28 adj[i].clear();
29 vis[i]=0;
30 }
31 for(int i=0;i<m;i++)
32 {
33 cin>>u>>v;
34 adj[u].pb(v);
35 adj[v].pb(u);
36 }
37 int ht[n];
38 memset(ht,INT_MAX,sizeof(ht));
39 ht[0] = 0;
40
41 priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;
42 pq.push({0,0});
43 pair<int,int> tmp;
44 int x,y;
45 int visit[n];
46 memset(visit,0,sizeof(visit));
47 while(!pq.empty())
48 {
49 tmp=pq.top();pq.pop();
50 x=tmp.first;
51 y=tmp.second;
52 if(visit[y])continue;
53 visit[y]=1;
54 ht[y]=x;
55 for(auto i:adj[y])
56 {
57 if(!visit[i])
58 {
59 pq.push({ht[y]+1,i});
60 }
61 }
62
63 }
64 for(int i=1;i<n;i++)
65 {
66 if(!visit[i])
67 ht[i]=-1;
68 }
69 for(int i=1;i<n;i++)
70 cout<<ht[i]<<"\n";
71}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected