Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 다이나믹 프로그래밍
- DFS
- 브루트포스
- 그리디 알고리즘
- 그래프
- Unreal Engine 5
- 자료구조
- 알고리즘
- 유니온 파인드
- 백준
- VR
- BFS
- Team Fortress 2
- c++
- 구현
- 우선순위 큐
- 백트래킹
- 재귀
- 투 포인터
- 누적 합
- 스택
- 시뮬레이션
- 유니티
- XR Interaction Toolkit
- 트리
- 정렬
- 다익스트라
- 문자열
- 수학
- ue5
Archives
- Today
- Total
1일1알
백준 1325번 효율적인 해킹 C++ 본문
A가 B를 신뢰하는 경우에 B를 해킹하면 A를 해킹할 수 있기 때문에
A와 B를 입력받았을 때 B->A 로 연결되어있다고 저장한 뒤 bfs로 탐색하여 문제를 해결하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int n, m;
vector<vector<int>> trust(10001, vector<int>());
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
int a, b;
for (int i = 0; i < m; i++) {
cin >> a >> b;
trust[b].push_back(a);
}
int max_cnt = -1;
vector<int> ans;
for (int i = 1; i <= 10000; i++) {
bool visited[10001] = { false };
visited[i] = true;
int cnt = 0;
queue<int> q;
q.push(i);
while (!q.empty()) {
auto curr = q.front();
q.pop();
cnt++;
for (auto next : trust[curr]) {
if (!visited[next]) {
q.push(next);
visited[next] = true;
}
}
}
if (cnt == max_cnt) {
ans.push_back(i);
}
else if (cnt > max_cnt) {
ans.clear();
ans.push_back(i);
max_cnt = cnt;
}
}
sort(ans.begin(), ans.end());
for (auto val : ans) {
cout << val << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 1495번 기타리스트 C++ (0) | 2021.12.16 |
---|---|
백준 2011번 암호코드 C++ (0) | 2021.12.15 |
백준 2110번 공유기 설치 C++ (0) | 2021.12.13 |
백준 2343번 기타 레슨 C++ (0) | 2021.12.12 |
백준 1743번 음식물 피하기 C++ (0) | 2021.12.11 |