結果
問題 | No.1775 Love Triangle 2 |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-12-25 23:02:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 116 ms / 8,000 ms |
コード長 | 6,073 bytes |
コンパイル時間 | 1,097 ms |
コンパイル使用メモリ | 109,864 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 04:46:37 |
合計ジャッジ時間 | 6,880 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,812 KB |
testcase_01 | AC | 6 ms
6,940 KB |
testcase_02 | AC | 5 ms
6,940 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 103 ms
6,940 KB |
testcase_05 | AC | 111 ms
6,944 KB |
testcase_06 | AC | 110 ms
6,940 KB |
testcase_07 | AC | 47 ms
6,940 KB |
testcase_08 | AC | 104 ms
6,940 KB |
testcase_09 | AC | 13 ms
6,944 KB |
testcase_10 | AC | 13 ms
6,940 KB |
testcase_11 | AC | 14 ms
6,940 KB |
testcase_12 | AC | 15 ms
6,944 KB |
testcase_13 | AC | 19 ms
6,940 KB |
testcase_14 | AC | 22 ms
6,940 KB |
testcase_15 | AC | 33 ms
6,944 KB |
testcase_16 | AC | 38 ms
6,940 KB |
testcase_17 | AC | 59 ms
6,940 KB |
testcase_18 | AC | 99 ms
6,940 KB |
testcase_19 | AC | 14 ms
6,940 KB |
testcase_20 | AC | 14 ms
6,940 KB |
testcase_21 | AC | 14 ms
6,940 KB |
testcase_22 | AC | 17 ms
6,940 KB |
testcase_23 | AC | 18 ms
6,944 KB |
testcase_24 | AC | 14 ms
6,944 KB |
testcase_25 | AC | 17 ms
6,940 KB |
testcase_26 | AC | 20 ms
6,944 KB |
testcase_27 | AC | 17 ms
6,944 KB |
testcase_28 | AC | 21 ms
6,944 KB |
testcase_29 | AC | 116 ms
6,940 KB |
testcase_30 | AC | 98 ms
6,940 KB |
testcase_31 | AC | 76 ms
6,940 KB |
testcase_32 | AC | 57 ms
6,944 KB |
testcase_33 | AC | 40 ms
6,940 KB |
testcase_34 | AC | 41 ms
6,944 KB |
testcase_35 | AC | 31 ms
6,940 KB |
testcase_36 | AC | 21 ms
6,944 KB |
testcase_37 | AC | 16 ms
6,944 KB |
testcase_38 | AC | 12 ms
6,940 KB |
testcase_39 | AC | 103 ms
6,940 KB |
testcase_40 | AC | 83 ms
6,940 KB |
testcase_41 | AC | 66 ms
6,940 KB |
testcase_42 | AC | 53 ms
6,944 KB |
testcase_43 | AC | 40 ms
6,944 KB |
testcase_44 | AC | 42 ms
6,944 KB |
testcase_45 | AC | 30 ms
6,940 KB |
testcase_46 | AC | 25 ms
6,944 KB |
testcase_47 | AC | 18 ms
6,944 KB |
testcase_48 | AC | 14 ms
6,940 KB |
testcase_49 | AC | 96 ms
6,944 KB |
testcase_50 | AC | 96 ms
6,940 KB |
testcase_51 | AC | 75 ms
6,940 KB |
testcase_52 | AC | 56 ms
6,940 KB |
testcase_53 | AC | 40 ms
6,944 KB |
testcase_54 | AC | 40 ms
6,944 KB |
testcase_55 | AC | 29 ms
6,944 KB |
testcase_56 | AC | 22 ms
6,940 KB |
testcase_57 | AC | 17 ms
6,940 KB |
testcase_58 | AC | 13 ms
6,944 KB |
testcase_59 | AC | 95 ms
6,944 KB |
testcase_60 | AC | 82 ms
6,940 KB |
testcase_61 | AC | 66 ms
6,944 KB |
testcase_62 | AC | 53 ms
6,940 KB |
testcase_63 | AC | 41 ms
6,944 KB |
testcase_64 | AC | 31 ms
6,940 KB |
testcase_65 | AC | 24 ms
6,940 KB |
testcase_66 | AC | 18 ms
6,940 KB |
testcase_67 | AC | 15 ms
6,940 KB |
testcase_68 | AC | 14 ms
6,940 KB |
testcase_69 | AC | 13 ms
6,940 KB |
testcase_70 | AC | 13 ms
6,944 KB |
testcase_71 | AC | 13 ms
6,944 KB |
testcase_72 | AC | 13 ms
6,940 KB |
testcase_73 | AC | 13 ms
6,944 KB |
testcase_74 | AC | 13 ms
6,940 KB |
testcase_75 | AC | 13 ms
6,940 KB |
testcase_76 | AC | 13 ms
6,940 KB |
testcase_77 | AC | 13 ms
6,944 KB |
testcase_78 | AC | 13 ms
6,944 KB |
testcase_79 | AC | 15 ms
6,940 KB |
testcase_80 | AC | 15 ms
6,940 KB |
testcase_81 | AC | 14 ms
6,940 KB |
testcase_82 | AC | 14 ms
6,940 KB |
testcase_83 | AC | 15 ms
6,944 KB |
testcase_84 | AC | 14 ms
6,940 KB |
testcase_85 | AC | 14 ms
6,944 KB |
testcase_86 | AC | 15 ms
6,940 KB |
testcase_87 | AC | 14 ms
6,940 KB |
testcase_88 | AC | 14 ms
6,944 KB |
testcase_89 | AC | 12 ms
6,940 KB |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } //////////////////////////////////////////////////////////////////////////////// namespace nim { using u16 = unsigned short; using u32 = unsigned; using u64 = unsigned long long; template <int L> inline u64 mulSlow(u64 a, u64 b) { static constexpr int l = L >> 1; const u64 a0 = a & ((1ULL << l) - 1), a1 = a >> l; const u64 b0 = b & ((1ULL << l) - 1), b1 = b >> l; const u64 a0b0 = mulSlow<l>(a0, b0); return (a0b0 ^ mulSlow<l>(1ULL << (l - 1), mulSlow<l>(a1, b1))) | (a0b0 ^ mulSlow<l>(a0 ^ a1, b0 ^ b1)) << l; } template <> inline u64 mulSlow<1>(u64 a, u64 b) { return a & b; } constexpr u16 G16 = 10279U; u16 buf[4 * ((1 << 16) - 1) + 26]; u16 *exp = buf + (2 * ((1 << 16) - 1) + 18), *exp3 = exp + 3, *exp6 = exp + 6; int log[1 << 16]; struct Preparator { Preparator() { exp[0] = 1; for (int i = 1; i < (1 << 16) - 1; ++i) exp[i] = mulSlow<16>(exp[i - 1], G16); log[0] = -(((1 << 16) - 1) + 9); for (int i = 0; i < (1 << 16) - 1; ++i) log[exp[i]] = i; memcpy(exp + ((1 << 16) - 1), exp, ((1 << 16) - 1) * sizeof(u16)); memcpy(exp + 2 * ((1 << 16) - 1), exp, 8 * sizeof(u16)); } } preparator; inline u16 mul(u16 a, u16 b) { return exp[log[a] + log[b]]; } inline u32 mul(u32 a, u32 b) { const u16 a0 = a, a1 = a >> 16; const u16 b0 = b, b1 = b >> 16; const u16 a01 = a0 ^ a1; const u16 b01 = b0 ^ b1; const u16 a0b0 = mul(a0, b0); return (a0b0 ^ exp3[log[a1] + log[b1]]) | (u32)(a0b0 ^ mul(a01, b01)) << 16; } inline u64 mul(u64 a, u64 b) { u64 aa = a >> 16, aaa = a >> 32; u64 bb = b >> 16, bbb = b >> 32; const u16 a0 = a, a1 = aa, a2 = aaa, a3 = a >> 48; const u16 b0 = b, b1 = bb, b2 = bbb, b3 = b >> 48; aa ^= a; aaa ^= a; bb ^= b; bbb ^= b; const u16 a01 = aa, a23 = aa >> 32, a02 = aaa, a13 = aaa >> 16; const u16 b01 = bb, b23 = bb >> 32, b02 = bbb, b13 = bbb >> 16; const u16 a0123 = a01 ^ a23; const u16 b0123 = b01 ^ b23; const u16 a0b0 = mul(a0, b0), a23b23 = mul(a23, b23), a02b02 = mul(a02, b02); const u32 c = (a0b0 ^ exp3[log[a1] + log[b1]]) | (u32)(a0b0 ^ mul(a01, b01)) << 16; return (c ^ (exp6[log[mul(a2, b2) ^ a23b23]] | (u32)exp3[log[exp3[log[a3] + log[b3]] ^ a23b23]] << 16)) | (u64)(c ^ ((a02b02 ^ exp3[log[a13] + log[b13]]) | (u32)(a02b02 ^ mul(a0123, b0123)) << 16)) << 32; } } // namespace nim //////////////////////////////////////////////////////////////////////////////// unsigned xrand() { static unsigned x = 314159265, y = 358979323, z = 846264338, w = 327950288; unsigned t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } using namespace nim; constexpr int MAX_N = 110; int N, M; int X, Y, Z; vector<int> A, B; bool adj[MAX_N][MAX_N]; u64 C[MAX_N][MAX_N]; u64 dp[MAX_N][4][MAX_N]; u64 dpY[MAX_N][4][MAX_N]; u64 dpZ[MAX_N][4][MAX_N]; int main() { for (; ~scanf("%d%d", &N, &M); ) { scanf("%d%d%d", &X, &Y, &Z); --X; --Y; --Z; A.resize(M); B.resize(M); for (int i = 0; i < M; ++i) { scanf("%d%d", &A[i], &B[i]); --A[i]; --B[i]; } memset(adj, 0, sizeof(adj)); for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) { adj[u][v] = (u != v); } for (int i = 0; i < M; ++i) { adj[A[i]][B[i]] = adj[B[i]][A[i]] = false; } for (int u = 0; u < N; ++u) { adj[N][u] = adj[X][u]; adj[u][N] = adj[u][X]; } int ans = N + 1; for (int iter = 0; iter < 1; ++iter) { memset(C, 0, sizeof(C)); for (int u = 0; u <= N; ++u) for (int v = u + 1; v <= N; ++v) { u64 c = xrand(); c <<= 32; c |= xrand(); C[u][v] = C[v][u] = c; } memset(dp, 0, sizeof(dp)); memset(dpY, 0, sizeof(dpY)); memset(dpZ, 0, sizeof(dpZ)); dp[0][0][X] = 1; for (int l = 0; l < N; ++l) { for (int p = 0; p < 4; ++p) { for (int u = 0; u <= N; ++u) { for (int v = 0; v <= N; ++v) if (adj[u][v]) { const u64 prod = mul(dp[l][p][u], C[u][v]); if (v == Y) { if (!(p & 1)) { dpY[l + 1][p | 1][u] ^= prod; } } else if (v == Z) { if (!(p & 2)) { dpZ[l + 1][p | 2][u] ^= prod; } } else { dp[l + 1][p][v] ^= prod; } } } if (p & 1) { u64 sum = 0; for (int u = 0; u <= N; ++u) { sum ^= dpY[l][p][u]; } for (int u = 0; u <= N; ++u) if (adj[Y][u]) { dp[l + 1][p][u] ^= mul(sum ^ dpY[l][p][u], C[Y][u]); } } if (p & 2) { u64 sum = 0; for (int u = 0; u <= N; ++u) { sum ^= dpZ[l][p][u]; } for (int u = 0; u <= N; ++u) if (adj[Z][u]) { dp[l + 1][p][u] ^= mul(sum ^ dpZ[l][p][u], C[Z][u]); } } } } for (int l = 0; l <= N; ++l) { if (dp[l][3][N]) { chmin(ans, l); } } } printf("%d\n", (ans >= N + 1) ? -1 : ans); } return 0; }