import java.util.Scanner;
public class Main {
static int n, m;
static int arr[][] = new int [101][6];
static int[] res = new int [101];
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int i, j;
n = scan.nextInt();
m = scan.nextInt();
for (i = 0; i < m; i++) {
for (j = 0; j < 3; j++) {
arr[i][j] = scan.nextInt();
}
}
f(n,1);
for (i = 1; i < n; i++) {
if (res[i] != 0) {
System.out.println(i + " " + res[i]);
}
}
}
private static void f(int n,int cnt) {
int flag = 0;
int i;
for (i = 0; i < m; i++) {
if (arr[i][0] == n) {
flag = 1;
f(arr[i][1], cnt * arr[i][2]);
}
}
if (flag == 0) {
res[n] += cnt;
}
}
}
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=300&sca=2080
'정올문제소스코드' 카테고리의 다른 글
1490 : 다음 조합(next combination) (0) | 2022.03.18 |
---|---|
2817 : 로또(Lotto) (0) | 2022.03.18 |
1459 : 숫자고르기 (0) | 2021.12.05 |
1175 : 주사위 던지기2 (0) | 2021.12.05 |
1169 : 주사위 던지기1 (0) | 2021.12.05 |