-
Notifications
You must be signed in to change notification settings - Fork 1
/
sol.cpp
38 lines (36 loc) · 821 Bytes
/
sol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Written by: wyattwismer
#include <bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int n,m,s;
cin>>n>>m;
vector<vector<int>> gra(n);
while(m--){
int u,v;
cin>>u>>v;
u--;v--;
gra[u].push_back(v);
gra[v].push_back(u);
}
cin>>s; s--;
queue<int> q;
q.push(s);
vector<int> d(n,-1);
d[s] = 0;
while(!q.empty()){
int x = q.front();
q.pop();
for(auto nxt: gra[x]){
if(d[nxt] != -1) continue;
d[nxt] = d[x] + 6;
q.push(nxt);
}
}
for(int i=0; i<n; i++) if (i != s)
cout << d[i] << " ";
cout << endl;
}
}