We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 25af9ff commit fe3c033Copy full SHA for fe3c033
1 file changed
khj20006/202508/23 BOJ G5 그래프 탐색.md
@@ -0,0 +1,39 @@
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
+```
0 commit comments