File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+
5+ int main () {
6+ cin.tie(0)->sync_with_stdio(0);
7+ int N,M;
8+ cin>>N>>M;
9+ bool v[501][501]{};
10+ for(int i=0,a,b;i<M;i++) {
11+ cin>>a>>b;
12+ v[a][b] = v[b][a] = 1;
13+ }
14+ int Q;
15+ for(cin>>Q;Q--;) {
16+ int a,b,c;
17+ cin>>a>>b>>c;
18+ int d = a&1;
19+ v[b][c] = v[c][b] = d;
20+
21+ int ans[501]{};
22+ for(int i=1;i<=N;i++) ans[i] = -1;
23+ queue<pair<int,int>> q;
24+ q.emplace(1,0);
25+ bitset<501> vis;
26+ vis[1] = 1;
27+ while(!q.empty()) {
28+ auto [n,t] = q.front(); q.pop();
29+ ans[n] = t;
30+ for(int i=1;i<=N;i++) if(v[n][i] && !vis[i]) {
31+ vis[i] = 1;
32+ q.emplace(i,t+1);
33+ }
34+ }
35+ for(int i=1;i<=N;i++) cout<<ans[i]<<' ';
36+ cout<<'\n';
37+ }
38+ }
39+ ```
You can’t perform that action at this time.
0 commit comments