結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-08-13 22:18:22 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 248 ms / 2,500 ms |
コード長 | 2,952 bytes |
コンパイル時間 | 916 ms |
コンパイル使用メモリ | 115,276 KB |
実行使用メモリ | 23,732 KB |
最終ジャッジ日時 | 2023-09-04 13:38:18 |
合計ジャッジ時間 | 18,349 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,384 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 5 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 7 ms
4,380 KB |
testcase_08 | AC | 220 ms
21,636 KB |
testcase_09 | AC | 204 ms
18,736 KB |
testcase_10 | AC | 222 ms
20,160 KB |
testcase_11 | AC | 169 ms
15,124 KB |
testcase_12 | AC | 188 ms
16,156 KB |
testcase_13 | AC | 179 ms
15,612 KB |
testcase_14 | AC | 238 ms
21,964 KB |
testcase_15 | AC | 226 ms
19,944 KB |
testcase_16 | AC | 211 ms
19,120 KB |
testcase_17 | AC | 173 ms
16,476 KB |
testcase_18 | AC | 188 ms
16,172 KB |
testcase_19 | AC | 199 ms
20,380 KB |
testcase_20 | AC | 204 ms
18,596 KB |
testcase_21 | AC | 207 ms
20,424 KB |
testcase_22 | AC | 241 ms
20,444 KB |
testcase_23 | AC | 242 ms
23,136 KB |
testcase_24 | AC | 217 ms
19,048 KB |
testcase_25 | AC | 222 ms
20,644 KB |
testcase_26 | AC | 240 ms
20,420 KB |
testcase_27 | AC | 242 ms
20,648 KB |
testcase_28 | AC | 248 ms
21,704 KB |
testcase_29 | AC | 243 ms
21,720 KB |
testcase_30 | AC | 227 ms
19,596 KB |
testcase_31 | AC | 243 ms
21,232 KB |
testcase_32 | AC | 212 ms
21,500 KB |
testcase_33 | AC | 211 ms
18,848 KB |
testcase_34 | AC | 243 ms
22,972 KB |
testcase_35 | AC | 224 ms
20,840 KB |
testcase_36 | AC | 242 ms
22,748 KB |
testcase_37 | AC | 242 ms
23,732 KB |
testcase_38 | AC | 221 ms
19,712 KB |
testcase_39 | AC | 199 ms
15,916 KB |
testcase_40 | AC | 219 ms
18,288 KB |
testcase_41 | AC | 202 ms
18,940 KB |
testcase_42 | AC | 217 ms
17,812 KB |
testcase_43 | AC | 2 ms
4,380 KB |
testcase_44 | AC | 1 ms
4,380 KB |
testcase_45 | AC | 173 ms
14,300 KB |
testcase_46 | AC | 188 ms
15,380 KB |
testcase_47 | AC | 172 ms
15,028 KB |
testcase_48 | AC | 182 ms
14,524 KB |
testcase_49 | AC | 173 ms
15,024 KB |
testcase_50 | AC | 176 ms
14,300 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)); } int[] A, B; int[][] G; bool[] vis; int[] pari; int[] ans; bool dfs(int u, int ip) { vis[u] = true; pari[u] = ip; foreach (i; G[u]) { if (i != ip) { const v = A[i] ^ B[i] ^ u; if (vis[v]) { ans ~= i; for (int w = u; w != v; ) { const j = pari[w]; ans ~= j; w = A[j] ^ B[j] ^ w; } return true; } if (dfs(v, i)) { return true; } } } return false; } void main() { try { for (; ; ) { readLong(); readLong(); const M = readInt(); long[] X = new long[M]; long[] Y = new long[M]; foreach (i; 0 .. M) { X[i] = readLong(); Y[i] = readLong(); } const xs = X.dup.sort.uniq.array; const ys = Y.dup.sort.uniq.array; const xsLen = cast(int)(xs.length); const ysLen = cast(int)(ys.length); A = new int[M]; B = new int[M]; foreach (i; 0 .. M) { A[i] = xs.lowerBound(X[i]); B[i] = xsLen + ys.lowerBound(Y[i]); } G = new int[][xsLen + ysLen]; foreach (i; 0 .. M) { G[A[i]] ~= i; G[B[i]] ~= i; } vis = new bool[xsLen + ysLen]; pari = new int[xsLen + ysLen]; pari[] = -1; ans = null; foreach (u; 0 .. xsLen + ysLen) { if (!vis[u]) { if (dfs(u, -1)) { break; } } } if (ans) { if (Y[ans[0]] != Y[ans[1]]) { ans = ans[1 .. $] ~ ans[0]; } writeln(ans.length); foreach (index, i; ans) { if (index > 0) write(" "); write(i + 1); } writeln; } else { writeln(-1); } } } catch (EOFException e) { } }