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
- 유니온 파인드
- 문자열
- XR Interaction Toolkit
- 브루트포스
- 재귀
- 시뮬레이션
- 알고리즘
- ue5
- c++
- BFS
- 구현
- 정렬
- 자료구조
- 유니티
- 백트래킹
- 그래프
- 다익스트라
- 트리
- 우선순위 큐
- 누적 합
- Team Fortress 2
- VR
- 다이나믹 프로그래밍
- 그리디 알고리즘
Archives
- Today
- Total
1일1알
백준 2056번 작업 C++ 본문
https://www.acmicpc.net/problem/2056
2056번: 작업
수행해야 할 작업 N개 (3 ≤ N ≤ 10000)가 있다. 각각의 작업마다 걸리는 시간(1 ≤ 시간 ≤ 100)이 정수로 주어진다. 몇몇 작업들 사이에는 선행 관계라는 게 있어서, 어떤 작업을 수행하기 위해
www.acmicpc.net
위상 정렬
#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 <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
vector<int> inDegree;
vector<int> times;
vector<int> res;
vector<vector<int>> graph;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
inDegree = vector<int>(n + 1, 0);
times = vector<int>(n + 1);
res = vector<int>(n + 1, 0);
graph = vector<vector<int>>(n + 1, vector<int>());
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
times[i] = t;
int cnt;
cin >> cnt;
for (int j = 0; j < cnt; j++) {
int before;
cin >> before;
graph[before].push_back(i);
inDegree[i]++;
}
}
queue<int> q;
for (int i = 1; i <= n; i++) {
if (inDegree[i] == 0) q.push(i);
}
int ans = 0;
while (!q.empty()) {
int curr = q.front();
q.pop();
for (auto next : graph[curr]) {
res[next] = max(res[next], res[curr] + times[curr]);
if (--inDegree[next] == 0) q.push(next);
}
}
for (int i = 1; i <= n; i++) {
res[i] += times[i];
ans = max(ans, res[i]);
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 17352번 여러분의 다리가 되어 드리겠습니다! C++ (0) | 2022.10.12 |
---|---|
백준 10974번 모든 순열 C++ (0) | 2022.10.11 |
백준 5397번 키로거 C++ (0) | 2022.10.09 |
백준 1699번 제곱수의 합 C++ (0) | 2022.10.08 |
백준 17822번 원판 돌리기 C++ (0) | 2022.10.04 |