結果

問題 No.1023 Cyclic Tour
ユーザー htensaihtensai
提出日時 2020-04-30 10:28:34
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,209 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 78,188 KB
実行使用メモリ 92,988 KB
最終ジャッジ日時 2024-05-08 12:40:10
合計ジャッジ時間 31,949 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
45,864 KB
testcase_01 AC 116 ms
41,116 KB
testcase_02 AC 113 ms
40,428 KB
testcase_03 AC 115 ms
41,180 KB
testcase_04 AC 1,036 ms
71,808 KB
testcase_05 AC 1,081 ms
71,976 KB
testcase_06 AC 1,193 ms
73,040 KB
testcase_07 AC 1,129 ms
72,668 KB
testcase_08 AC 1,055 ms
70,020 KB
testcase_09 AC 1,051 ms
69,012 KB
testcase_10 AC 1,047 ms
67,020 KB
testcase_11 TLE -
testcase_12 AC 1,701 ms
66,440 KB
testcase_13 AC 1,663 ms
66,080 KB
testcase_14 WA -
testcase_15 AC 1,633 ms
66,156 KB
testcase_16 AC 1,523 ms
72,220 KB
testcase_17 AC 1,384 ms
72,064 KB
testcase_18 AC 1,535 ms
72,108 KB
testcase_19 AC 1,401 ms
70,840 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();
            graph.get(a).add(b);
            if (c == 1) {
                graph.get(b).add(a);
            }
        }
        for (int i = 0; i < n; i++) {
            search(i, -1, new boolean[n]);
        }
        System.out.println("No");
    }
    
    static void search(int idx, int from, boolean[] visited) {
        if (visited[idx]) {
            System.out.println("Yes");
            System.exit(0);
        }
        visited[idx] = true;
        boolean flag = true;
        for (int x : graph.get(idx)) {
            if (x == from && flag) {
                flag = false;
               continue;
             }
            search(x, idx, visited);
        }
        visited[idx] = false;
    }
}
0