일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- c++
- object detection
- dfs
- 가끔은_말로
- 너비 우선 탐색
- dropout
- 미래는_현재와_과거로
- DP
- 회고록
- NEXT
- BFS
- 플로이드 와샬
- 이분 탐색
- 백트래킹
- lazy propagation
- 조합론
- back propagation
- 우선 순위 큐
- pytorch
- tensorflow
- Overfitting
- 자바스크립트
Archives
- Today
- Total
Doby's Lab
백준 13232번: Domain clusters (C++) 본문
https://www.acmicpc.net/problem/13232
13232번: Domain clusters
We are analyzing how the domains on the Internet connect to each other. A domain is the part of a URL that comes before the / character. Examples of domains are: twitter.com, aipo.computing.dcu.ieor google.com. A domain d1 is connected to a domain d2 if th
www.acmicpc.net
Solved By: SCC(Kosaraju Algorithm)
아직은 SCC 알고리즘 중 Kosaraju Algorithm이 더 익숙해서 Kosaraju Algorithm을 이용하여 풀어보았습니다.
SCC 중에 사이즈가 제일 큰 값을 도출해내면 되는 문제였습니다. SCC 문제 중 크게 어려웠던 문제는 아니었던 거 같습니다.
Tarjan Algorithm을 이용하여 SCC 군집 노드끼리의 위상 정렬을 통해 풀 수 있는 문제들을 빨리 풀어봐야 할 거 같습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#define MAX 5001
using namespace std;
int n, m;
vector<int> adj[MAX];
vector<int> radj[MAX];
bool visited[MAX];
stack<int> s;
int numSCC = 0;
vector<int> SCC[MAX];
void dfs(int node){
if(visited[node]) return;
visited[node] = 1;
for(int i = 0; i < adj[node].size(); i++){
int next = adj[node][i];
if(!visited[next]) dfs(next);
}
s.push(node);
}
void rdfs(int node){
if(visited[node]) return;
visited[node] = 1;
for(int i = 0; i < radj[node].size(); i++){
int next = radj[node][i];
if(!visited[next]) rdfs(next);
}
SCC[numSCC].push_back(node);
return;
}
void makeSCC(){
for(int i = 1; i <= n; i++) visited[i] = 0;
while(!s.empty()){
int now = s.top();
s.pop();
if(visited[now]) continue;
rdfs(now);
numSCC++;
}
return;
}
void kosaraju(){
for(int i = 1; i <= n; i++){
if(!visited[i]) dfs(i);
}
makeSCC();
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
radj[b].push_back(a);
}
kosaraju();
int result = 0;
for(int i = 0; i < numSCC; i++){
result = max(result, (int)SCC[i].size());
}
cout << result;
return 0;
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 4196번: 도미노 (C++) (0) | 2022.04.23 |
---|---|
백준 17403번: 가장 높고 넓은 성 (C++) (0) | 2022.04.21 |
백준 6194번: Buliding the Moat (C++) (0) | 2022.04.17 |
백준 6850번: Cows (C++) (0) | 2022.04.17 |
백준 10903번: Wall construction (C++) (0) | 2022.04.16 |