Skip to main content

Bridge

BOJ 1734 ꡐ톡 체계

·405 words·2 mins
πŸ“ 문제 정보 # 링크: https://www.acmicpc.net/problem/1734 🧐 κ΄€μ°° 및 μ ‘κ·Ό # 무ν–₯ κ·Έλž˜ν”„ $G = (V, E)$κ°€ μ£Όμ–΄μ§„λ‹€. μ—¬κΈ°μ„œ 두가지 쿼리가 μ£Όμ–΄μ§„λ‹€. κ°„μ„  $e \in E$ ν•˜λ‚˜λ₯Ό 없앴을 λ•Œ, 정점 $A, B$의 μ—°κ²°μ„± νŒμ • 정점 $v \in V$ ν•˜λ‚˜λ₯Ό 없앴을 λ•Œ, 정점 $A, B$의 μ—°κ²°μ„± νŒμ • 각각 μ‚΄νŽ΄λ³΄μž. λ¨Όμ €, λ¬Έμ œμ‘°κ±΄μ— μ˜ν•΄ μ»΄ν¬λ„ŒνŠΈλŠ” ν•˜λ‚˜μ΄λ―€λ‘œ A, BλŠ” 기본적으둜 μ—°κ²°λ˜μ–΄μžˆλ‹€κ³  νŒλ‹¨ν•˜μž.

BOJ 14675 λ‹¨μ ˆμ κ³Ό λ‹¨μ ˆμ„ 

·118 words·1 min
πŸ“ 문제 정보 # 링크: https://www.acmicpc.net/problem/14675 🧐 κ΄€μ°° 및 μ ‘κ·Ό # νŠΈλ¦¬μ—μ„œμ˜ λ‹¨μ ˆμ κ³Ό λ‹¨μ ˆμ„ μ„ μƒκ°ν•΄λ³΄μž. νŠΈλ¦¬μ—μ„œ λͺ¨λ“  간선은 λ‹¨μ ˆμ„ μ΄λ‹€. 사이클 μ—†λŠ” μ—°κ²° κ·Έλž˜ν”„λ‹ˆκΉŒ νŠΈλ¦¬μ—μ„œ λ¦¬ν”„λ…Έλ“œλ₯Ό μ œμ™Έν•œ λͺ¨λ“  λ…Έλ“œλŠ” λ‹¨μ ˆμ μ΄λ‹€. μœ„μ™€ μ΄μœ κ°€ κ°™λ‹€. 우회경둜둜 μ“Έ back edgeκ°€ μ—†λ‹€. πŸ’» 풀이 # μ½”λ“œ (C++): void solve(){ cin >> N; rep(i, 0, N-1){ int u, v; cin >> u >> v; links[u].push_back(v); links[v].push_back(u); } cin >> Q; while(Q--){ int t, k; cin >> t >> k; if(t == 1) cout << ((int)links[k].size() == 1 ? "no\n" : "yes\n"); else cout << "yes\n"; } } πŸ”’ κ΅¬ν˜„ μ½”λ“œ 잠금

BOJ 10891 Cactus? Not cactus?

·175 words·1 min
πŸ“ 문제 정보 # 링크: https://www.acmicpc.net/problem/10891 🧐 κ΄€μ°° 및 μ ‘κ·Ό # μ–΄λ–€ 정점이 μ΅œλŒ€ ν•œκ°œμ˜ μ‚¬μ΄ν΄μ—λ§Œ μ†ν•΄μžˆλ‹€λ©΄, ν•΄λ‹Ή κ·Έλž˜ν”„λŠ” 정점 선인μž₯이닀. $\text{DP}[i]$ : 정점 $i$의 λΆ€λͺ¨μ™€ 정점 $i$의 μžμ‹μ„ μž‡λŠ” tree edgeκ°€ μ•„λ‹Œ κ°„μ„ μ˜ 수라고 μ •μ˜ν•˜μž. μ–΄λ–€ κ·Έλž˜ν”„κ°€ 정점 선인μž₯일 ν•„μš”μΆ©λΆ„μ‘°κ±΄μ€ $\forall i$ 에 λŒ€ν•΄ $\text{DP}[i] \leq 1$인 것이닀. μ΄λŠ” DFS+λˆ„μ ν•©μ²˜λŸΌ 계산할 수 μžˆλ‹€. πŸ’» 풀이 # μ½”λ“œ (C++): void dfs(int c, int p, int d){ depth[c] = d; par[c] = p; DP[c] = 0; for(auto n: links[c]){ if(n == p) continue; if(depth[n] == 0){ dfs(n, c, d+1); DP[c] += DP[n]; } else if(depth[n] < depth[c]) DP[c]++; else DP[par[c]]--; } } void solve(){ cin >> N >> M; rep(i, 0, M){ int u, v; cin >> u >> v; links[u].push_back(v); links[v].push_back(u); } dfs(1, -1, 1); bool isCactus = true; rep(i, 1, N+1) if(DP[i] > 1) isCactus = false; if(isCactus) cout << "Cactus"; else cout << "Not cactus"; } πŸ”’ κ΅¬ν˜„ μ½”λ“œ 잠금

BOJ 10891 Cactus? Not cactus?

·175 words·1 min
πŸ“ 문제 정보 # 링크: https://www.acmicpc.net/problem/10891 🧐 κ΄€μ°° 및 μ ‘κ·Ό # μ–΄λ–€ 정점이 μ΅œλŒ€ ν•œκ°œμ˜ μ‚¬μ΄ν΄μ—λ§Œ μ†ν•΄μžˆλ‹€λ©΄, ν•΄λ‹Ή κ·Έλž˜ν”„λŠ” 정점 선인μž₯이닀. $\text{DP}[i]$ : 정점 $i$의 λΆ€λͺ¨μ™€ 정점 $i$의 μžμ‹μ„ μž‡λŠ” tree edgeκ°€ μ•„λ‹Œ κ°„μ„ μ˜ 수라고 μ •μ˜ν•˜μž. μ–΄λ–€ κ·Έλž˜ν”„κ°€ 정점 선인μž₯일 ν•„μš”μΆ©λΆ„μ‘°κ±΄μ€ $\forall i$ 에 λŒ€ν•΄ $\text{DP}[i] \leq 1$인 것이닀. μ΄λŠ” DFS+λˆ„μ ν•©μ²˜λŸΌ 계산할 수 μžˆλ‹€. πŸ’» 풀이 # μ½”λ“œ (C++): void dfs(int c, int p, int d){ depth[c] = d; par[c] = p; DP[c] = 0; for(auto n: links[c]){ if(n == p) continue; if(depth[n] == 0){ dfs(n, c, d+1); DP[c] += DP[n]; } else if(depth[n] < depth[c]) DP[c]++; else DP[par[c]]--; } } void solve(){ cin >> N >> M; rep(i, 0, M){ int u, v; cin >> u >> v; links[u].push_back(v); links[v].push_back(u); } dfs(1, -1, 1); bool isCactus = true; rep(i, 1, N+1) if(DP[i] > 1) isCactus = false; if(isCactus) cout << "Cactus"; else cout << "Not cactus"; } πŸ”’ κ΅¬ν˜„ μ½”λ“œ 잠금