ํฐ์คํ ๋ฆฌ ๋ทฐ
https://www.acmicpc.net/problem/2056
[๋ฌธ์ ํ์ด]
์ด์ ์ ํ์๋ ์์์ ๋ ฌ์ ์ฌ์ฉํ ๋ฐฑ์ค ๊ฒ์๊ฐ๋ฐ ๋ฌธ์ ๋ ๊ฑฐ์ ๋น์ทํ ๋ฌธ์ ์์ต๋๋ค.
ํ์ด๋ ๊ฒ์๊ฐ๋ฐ ํฌ์คํ ์ ์ฒจ๋ถํ๋๋ก ํ๊ฒ ์ต๋๋ค.
https://j-su2.tistory.com/4?category=1016202
[์ ๋ต ์ฝ๋]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static int N;
public static int[] degree;
public static int[] time;
public static int[] maxTime;
public static ArrayList<ArrayList<Integer>> graph = new ArrayList<ArrayList<Integer>>();
public static PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
degree = new int[N];
time = new int[N];
maxTime = new int[N];
for(int i=0;i<N;i++) {
graph.add(new ArrayList<Integer>());
}
for(int i=0;i<N;i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
time[i] = Integer.parseInt(st.nextToken());
// ์์กด ๊ด๊ณ์ ๋ฐ์
degree[i] = Integer.parseInt(st.nextToken());
if (degree[i] == 0) {
pq.add(i);
}
for (int j = 0; j < degree[i]; j++) {
// 0๋ฒ~N-1๋ฒ์ผ๋ก ๋ฃ๊ธฐ ์ํด์ -1 ํด์ค
int num = Integer.parseInt(st.nextToken());
graph.get(num - 1).add(i);
}
}
findTime();
Arrays.sort(time);
System.out.println(time[N-1]);
}
public static void findTime() {
while(!pq.isEmpty()) {
int p = pq.poll();
for(Integer i:graph.get(p)) {
maxTime[i] = Math.max(maxTime[i], time[p]);
degree[i] -= 1;
if(degree[i] == 0) {
time[i] += maxTime[i];
pq.add(i);
}
}
}
}
}
'Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] ๋ฐฑ์ค 2461๋ฒ - ๋ํ ์ ์ (0) | 2022.06.05 |
---|---|
[Java] ๋ฐฑ์ค 2564๋ฒ - ๊ฒฝ๋น์ (0) | 2022.06.05 |
[Java] ๋ฐฑ์ค 19237๋ฒ - ์ด๋ฅธ ์์ด (0) | 2022.05.29 |
[Java] ๋ฐฑ์ค 1516๋ฒ - ๊ฒ์ ๊ฐ๋ฐ (1) | 2022.05.29 |
[Java] ๋ฐฑ์ค 1725๋ฒ - ํ์คํ ๊ทธ๋จ (0) | 2022.05.29 |
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- 2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด
- git
- ์ ์ญ ๋ณ์
- ๋ฐฑ์ค node.js
- map
- ๋ฐฑ์ค
- Baekjoon
- ์ฝ๋ฉํ ์คํธ
- JavaScript
- ๋ฐฑ์ค javascript
- ๋คํธ์ํฌ
- ํฌํฌ์ธํฐ
- ๋ ์์ปฌ ํ๊ฒฝ
- ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ
- http
- ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ
- ์ด๋ถํ์
- ํจ์ํ ํ๋ก๊ทธ๋๋ฐ
- ์นด์นด์ค ์ธํด
- ํ๋ก๊ทธ๋๋จธ์ค
- ํ๋กํผํฐ
- ์๊ณ ๋ฆฌ์ฆ
- fp
- ๋ชจ๋ ์๋ฐ์คํฌ๋ฆฝํธ deep dive
- ์๋ฐ
- ์๋ฐ์คํฌ๋ฆฝํธ
- TDD
- ์ด์์ฒด์
- ๋์์ธ ํจํด
- ํ๋กํ ์ฝ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
29 | 30 | 31 |
๊ธ ๋ณด๊ดํจ