結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-08-13 22:18:22 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 227 ms / 2,500 ms |
コード長 | 2,952 bytes |
コンパイル時間 | 1,053 ms |
コンパイル使用メモリ | 132,036 KB |
実行使用メモリ | 22,632 KB |
最終ジャッジ日時 | 2024-06-22 12:05:00 |
合計ジャッジ時間 | 13,134 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 5 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 7 ms
6,944 KB |
testcase_08 | AC | 190 ms
19,544 KB |
testcase_09 | AC | 182 ms
17,784 KB |
testcase_10 | AC | 194 ms
21,100 KB |
testcase_11 | AC | 149 ms
15,256 KB |
testcase_12 | AC | 161 ms
14,216 KB |
testcase_13 | AC | 154 ms
15,904 KB |
testcase_14 | AC | 197 ms
20,448 KB |
testcase_15 | AC | 195 ms
19,544 KB |
testcase_16 | AC | 181 ms
18,712 KB |
testcase_17 | AC | 151 ms
17,404 KB |
testcase_18 | AC | 161 ms
17,384 KB |
testcase_19 | AC | 169 ms
21,508 KB |
testcase_20 | AC | 169 ms
18,248 KB |
testcase_21 | AC | 175 ms
20,296 KB |
testcase_22 | AC | 200 ms
19,916 KB |
testcase_23 | AC | 205 ms
20,680 KB |
testcase_24 | AC | 178 ms
18,248 KB |
testcase_25 | AC | 188 ms
19,740 KB |
testcase_26 | AC | 204 ms
20,168 KB |
testcase_27 | AC | 207 ms
21,020 KB |
testcase_28 | AC | 205 ms
21,192 KB |
testcase_29 | AC | 227 ms
20,940 KB |
testcase_30 | AC | 196 ms
21,212 KB |
testcase_31 | AC | 206 ms
20,808 KB |
testcase_32 | AC | 179 ms
22,632 KB |
testcase_33 | AC | 182 ms
20,948 KB |
testcase_34 | AC | 203 ms
20,940 KB |
testcase_35 | AC | 191 ms
19,148 KB |
testcase_36 | AC | 206 ms
21,060 KB |
testcase_37 | AC | 207 ms
21,188 KB |
testcase_38 | AC | 187 ms
17,864 KB |
testcase_39 | AC | 164 ms
17,264 KB |
testcase_40 | AC | 190 ms
17,096 KB |
testcase_41 | AC | 171 ms
16,076 KB |
testcase_42 | AC | 183 ms
17,096 KB |
testcase_43 | AC | 1 ms
6,944 KB |
testcase_44 | AC | 1 ms
6,940 KB |
testcase_45 | AC | 148 ms
14,360 KB |
testcase_46 | AC | 165 ms
12,680 KB |
testcase_47 | AC | 153 ms
14,696 KB |
testcase_48 | AC | 159 ms
14,504 KB |
testcase_49 | AC | 154 ms
14,264 KB |
testcase_50 | AC | 152 ms
14,856 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) { } }