結果
問題 | No.1023 Cyclic Tour |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-04-10 21:52:30 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,570 bytes |
コンパイル時間 | 1,651 ms |
コンパイル使用メモリ | 109,584 KB |
実行使用メモリ | 28,020 KB |
最終ジャッジ日時 | 2023-09-04 07:14:51 |
合計ジャッジ時間 | 19,169 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 185 ms
13,192 KB |
testcase_05 | AC | 187 ms
15,484 KB |
testcase_06 | AC | 223 ms
17,876 KB |
testcase_07 | AC | 202 ms
17,716 KB |
testcase_08 | AC | 154 ms
12,172 KB |
testcase_09 | AC | 152 ms
10,136 KB |
testcase_10 | AC | 154 ms
10,192 KB |
testcase_11 | AC | 160 ms
12,204 KB |
testcase_12 | AC | 138 ms
11,448 KB |
testcase_13 | AC | 131 ms
11,720 KB |
testcase_14 | AC | 131 ms
11,624 KB |
testcase_15 | AC | 133 ms
9,892 KB |
testcase_16 | AC | 256 ms
17,568 KB |
testcase_17 | AC | 263 ms
16,920 KB |
testcase_18 | AC | 269 ms
18,464 KB |
testcase_19 | AC | 254 ms
17,424 KB |
testcase_20 | AC | 315 ms
16,236 KB |
testcase_21 | AC | 319 ms
16,560 KB |
testcase_22 | AC | 297 ms
14,708 KB |
testcase_23 | AC | 306 ms
16,180 KB |
testcase_24 | AC | 282 ms
16,004 KB |
testcase_25 | AC | 317 ms
15,004 KB |
testcase_26 | AC | 319 ms
17,080 KB |
testcase_27 | AC | 297 ms
18,412 KB |
testcase_28 | AC | 273 ms
14,916 KB |
testcase_29 | AC | 255 ms
13,476 KB |
testcase_30 | AC | 285 ms
14,868 KB |
testcase_31 | AC | 270 ms
16,496 KB |
testcase_32 | AC | 277 ms
20,112 KB |
testcase_33 | AC | 300 ms
17,024 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 308 ms
16,248 KB |
testcase_37 | AC | 291 ms
18,764 KB |
testcase_38 | AC | 258 ms
16,160 KB |
testcase_39 | AC | 296 ms
14,628 KB |
testcase_40 | AC | 289 ms
14,768 KB |
testcase_41 | AC | 285 ms
16,172 KB |
testcase_42 | AC | 344 ms
15,968 KB |
testcase_43 | AC | 253 ms
14,668 KB |
testcase_44 | AC | 193 ms
13,724 KB |
testcase_45 | AC | 146 ms
27,116 KB |
testcase_46 | AC | 149 ms
28,020 KB |
testcase_47 | AC | 166 ms
27,912 KB |
testcase_48 | AC | 275 ms
17,068 KB |
testcase_49 | AC | 277 ms
17,380 KB |
testcase_50 | AC | 273 ms
16,480 KB |
testcase_51 | AC | 275 ms
18,116 KB |
testcase_52 | AC | 276 ms
16,796 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) { } }