Submission #2544813
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define ri rd<int> #define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i) #define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i) #define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i) const int maxN = 1e5 + 7; const int maxS = (1 << 15) + 3; template<class T> T rd() { bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0; T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x; } int n, m; int a[maxN]; bool ok[maxS]; int f[maxS]; int main() { m = n = ri(); For (i, 1, n) { int x = ri() + 1, y = ri() + 1, d = ri(); a[x] ^= d; a[y] ^= d; } sort(a+1, a+n+1, greater<int>()); int res = 0, mask = 0; for (; n > 0 && a[n] == 0; --n) ++res; while (n > 0) { for (; n >= 2 && a[n] == a[n-1]; n -= 2) ++res; if (n > 1) mask |= 1 << (a[n--] - 1); } for (int s = mask; s; (--s) &= mask) { int tp = 0; rep (i, 1, 15) if (s >> (i-1) & 1) tp ^= i; ok[s] = tp == 0; } ok[0] = true; rep (s, 1, mask) if ((mask & s) == s && ok[s]){ for (int t = s; t; (--t) &= s) if (ok[t] && ok[s^t]) { f[s] = max(f[s], f[s ^ t] + 1); } } res += f[mask]; printf("%d\n", m - res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - XOR Tree |
User | acha |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1286 Byte |
Status | TLE |
Exec Time | 2103 ms |
Memory | 640 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1000 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt |
All | 0_000.txt, 0_001.txt, 1_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
1_002.txt | AC | 13 ms | 640 KB |
1_003.txt | AC | 14 ms | 640 KB |
1_004.txt | TLE | 2103 ms | 640 KB |
1_005.txt | AC | 15 ms | 640 KB |
1_006.txt | TLE | 2103 ms | 640 KB |
1_007.txt | AC | 15 ms | 640 KB |
1_008.txt | AC | 15 ms | 640 KB |
1_009.txt | TLE | 2103 ms | 640 KB |
1_010.txt | TLE | 2103 ms | 640 KB |
1_011.txt | TLE | 2103 ms | 640 KB |
1_012.txt | AC | 15 ms | 640 KB |
1_013.txt | TLE | 2103 ms | 640 KB |
1_014.txt | TLE | 2103 ms | 640 KB |
1_015.txt | AC | 16 ms | 640 KB |
1_016.txt | TLE | 2103 ms | 640 KB |
1_017.txt | AC | 15 ms | 640 KB |
1_018.txt | TLE | 2103 ms | 640 KB |
1_019.txt | AC | 15 ms | 640 KB |
1_020.txt | TLE | 2103 ms | 640 KB |
1_021.txt | AC | 15 ms | 640 KB |
1_022.txt | AC | 16 ms | 640 KB |
1_023.txt | TLE | 2103 ms | 640 KB |
1_024.txt | TLE | 2103 ms | 640 KB |
1_025.txt | TLE | 2103 ms | 640 KB |
1_026.txt | AC | 14 ms | 640 KB |
1_027.txt | AC | 15 ms | 640 KB |
1_028.txt | AC | 16 ms | 640 KB |
1_029.txt | AC | 15 ms | 640 KB |
1_030.txt | AC | 16 ms | 640 KB |
1_031.txt | AC | 15 ms | 640 KB |
1_032.txt | TLE | 2103 ms | 640 KB |
1_033.txt | AC | 15 ms | 640 KB |
1_034.txt | TLE | 2103 ms | 640 KB |
1_035.txt | AC | 16 ms | 640 KB |
1_036.txt | TLE | 2103 ms | 640 KB |
1_037.txt | AC | 16 ms | 640 KB |
1_038.txt | AC | 16 ms | 640 KB |
1_039.txt | AC | 16 ms | 640 KB |
1_040.txt | AC | 15 ms | 640 KB |
1_041.txt | AC | 15 ms | 640 KB |
1_042.txt | TLE | 2103 ms | 640 KB |