結果
問題 | No.1023 Cyclic Tour |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-04-10 21:52:30 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,570 bytes |
コンパイル時間 | 800 ms |
コンパイル使用メモリ | 123,256 KB |
実行使用メモリ | 27,340 KB |
最終ジャッジ日時 | 2024-06-22 06:32:57 |
合計ジャッジ時間 | 13,835 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 140 ms
13,448 KB |
testcase_05 | AC | 134 ms
14,988 KB |
testcase_06 | AC | 156 ms
16,940 KB |
testcase_07 | AC | 144 ms
17,180 KB |
testcase_08 | AC | 115 ms
11,908 KB |
testcase_09 | AC | 109 ms
9,772 KB |
testcase_10 | AC | 112 ms
9,860 KB |
testcase_11 | AC | 125 ms
12,792 KB |
testcase_12 | AC | 105 ms
12,908 KB |
testcase_13 | AC | 98 ms
9,488 KB |
testcase_14 | AC | 100 ms
9,436 KB |
testcase_15 | AC | 103 ms
9,564 KB |
testcase_16 | AC | 198 ms
17,492 KB |
testcase_17 | AC | 199 ms
17,384 KB |
testcase_18 | AC | 202 ms
16,676 KB |
testcase_19 | AC | 194 ms
17,208 KB |
testcase_20 | AC | 235 ms
14,496 KB |
testcase_21 | AC | 246 ms
15,284 KB |
testcase_22 | AC | 228 ms
14,692 KB |
testcase_23 | AC | 239 ms
14,756 KB |
testcase_24 | AC | 224 ms
15,276 KB |
testcase_25 | AC | 247 ms
15,960 KB |
testcase_26 | AC | 247 ms
16,300 KB |
testcase_27 | AC | 238 ms
17,704 KB |
testcase_28 | AC | 218 ms
14,552 KB |
testcase_29 | AC | 199 ms
13,728 KB |
testcase_30 | AC | 213 ms
14,692 KB |
testcase_31 | AC | 200 ms
16,104 KB |
testcase_32 | AC | 207 ms
19,180 KB |
testcase_33 | AC | 221 ms
16,232 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 232 ms
16,784 KB |
testcase_37 | AC | 227 ms
17,528 KB |
testcase_38 | AC | 206 ms
15,492 KB |
testcase_39 | AC | 222 ms
14,004 KB |
testcase_40 | AC | 233 ms
14,412 KB |
testcase_41 | AC | 217 ms
14,852 KB |
testcase_42 | AC | 242 ms
14,440 KB |
testcase_43 | AC | 207 ms
13,780 KB |
testcase_44 | AC | 143 ms
13,472 KB |
testcase_45 | AC | 116 ms
27,036 KB |
testcase_46 | AC | 116 ms
26,888 KB |
testcase_47 | AC | 131 ms
27,340 KB |
testcase_48 | AC | 228 ms
16,940 KB |
testcase_49 | AC | 218 ms
17,220 KB |
testcase_50 | AC | 218 ms
17,656 KB |
testcase_51 | AC | 217 ms
17,644 KB |
testcase_52 | AC | 222 ms
16,512 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } Tuple!(int, int[]) scc(in int[][][] graph) { const n = cast(int)(graph[0].length); int compN; auto compIds = new int[n]; int[] us; void dfs(int s, int u, int a, int b) { if (compIds[u] == a) { compIds[u] = b; foreach (v; graph[s][u]) { dfs(s, v, a, b); } if (s == 0) { us ~= u; } } } foreach (u; 0 .. n) { dfs(0, u, 0, -1); } foreach_reverse (u; us) { if (compIds[u] == -1) { dfs(1, u, -1, compN); ++compN; } } return tuple(compN, compIds); } void main() { try { for (; ; ) { const N = readInt(); const M = readInt(); auto A = new int[M]; auto B = new int[M]; auto C = new int[M]; foreach (i; 0 .. M) { A[i] = readInt() - 1; B[i] = readInt() - 1; C[i] = readInt(); } auto graph = new int[][][](2, N); void ae(int u, int v) { graph[0][u] ~= v; graph[1][v] ~= u; } foreach (i; 0 .. M) { if (C[i] == 1) { ae(A[i], B[i]); ae(B[i], A[i]); } else { ae(A[i], B[i]); } } const res = scc(graph); bool ans; foreach (i; 0 .. M) { if (C[i] == 2) { ans = ans || (res[1][A[i]] == res[1][B[i]]); } } writeln(ans ? "Yes" : "No"); } } catch (EOFException e) { } }