일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 분할 정복
- 2023
- DP
- object detection
- 알고리즘
- NEXT
- c++
- 너비 우선 탐색
- 조합론
- 자바스크립트
- lazy propagation
- 다익스트라
- Overfitting
- 문자열
- BFS
- 플로이드 와샬
- 크루스칼
- 가끔은 말로
- 가끔은_말로
- 회고록
- back propagation
- dfs
- 백트래킹
- 세그먼트 트리
- pytorch
- 우선 순위 큐
- 이분 탐색
- 미래는_현재와_과거로
- dropout
- tensorflow
Archives
- Today
- Total
Doby's Lab
백준 10292번: Man in the Middle (C++) 본문
https://www.acmicpc.net/problem/10292
10292번: Man in the Middle
Nowadays, social networks are one of most active research topic. A social network represents friendships between people. We say that two people are direct friends if they accept each other as friends. But friendship is an amazing thing. It is possible that
www.acmicpc.net
Solved By: Articulation
주어진 Directed Graph 가운데 Articulation이 존재하는지 찾는 문제였습니다. 존재 여부는 쿼리마다 flag변수를 사용하여 존재한다면 true로 할당하고, Articulation을 구현하여 문제를 풀 수 있었습니다.
#include <iostream>
#include <vector>
#define MAX 30001
using namespace std;
int T;
int n, m;
vector<int> adj[MAX];
int order = 0;
int visitedOrder[MAX];
bool flag = false;
int dfs(int now, bool isRoot){
int minOrder = visitedOrder[now] = ++order;
int child = 0;
for(int i = 0; i < adj[now].size(); i++){
int next = adj[now][i];
if(visitedOrder[next]){
minOrder = min(minOrder, visitedOrder[next]);
}
else{
child++;
int childMinOrder = dfs(next, false);
if(!isRoot && visitedOrder[now] <= childMinOrder){
flag = true;
}
minOrder = min(minOrder, childMinOrder);
}
}
if(isRoot && child >= 2){
flag = true;
}
return minOrder;
}
int main(){
cin >> T;
for(int t = 0; t < T; t++){
cin >> n >> m;
// init
order = 0;
flag = false;
for(int i = 0; i < MAX; i++){
adj[i].clear();
visitedOrder[i] = 0;
}
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, true);
cout << (flag ? "YES" : "NO") << '\n';
}
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 10971번: 외판원 순회 2 (C++) (0) | 2022.07.17 |
---|---|
백준 5651번: 완전 중요한 간선 (C++) (0) | 2022.07.17 |
백준 4195번: 친구 네트워크 (C++) (0) | 2022.07.09 |
백준 11266번: 단절점 (C++, Resolve) (0) | 2022.07.07 |
백준 17204번: 죽음의 게임 (Python) (0) | 2022.07.07 |