Submission #26520165
Source Code Expand
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define pb emplace_back
#define mp std::make_pair
#define fi first
#define se second
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
const ll mod = 998244353;
ll Add(ll x, ll y) { return (x+y>=mod) ? (x+y-mod) : (x+y); }
ll Mul(ll x, ll y) { return x * y % mod; }
ll Mod(ll x) { return x < 0 ? (x + mod) : (x >= mod ? (x-mod) : x); }
ll cadd(ll &x, ll y) { return x = (x+y>=mod) ? (x+y-mod) : (x+y); }
template <typename T> T Max(T x, T y) { return x > y ? x : y; }
template <typename T> T Min(T x, T y) { return x < y ? x : y; }
template <typename T>
T &read(T &r) {
r = 0; bool w = 0; char ch = getchar();
while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar();
while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar();
return r = w ? -r : r;
}
const int N = 100010;
int n, ent, head[N];
int d[N], f[N];
struct Edge {
int next, to, v1, v2;
}e[N << 1];
inline void add(int x, int y, int w1, int w2) {
e[++ent].to = y; e[ent].next = head[x]; e[ent].v1 = w1; e[ent].v2 = w2; head[x] = ent;
}
void dfs(int x, int fa, int h1, int h2) {
d[x] = h1; f[x] = h2;
for(int i = head[x]; i; i = e[i].next) {
int v = e[i].to; if(v == fa) continue ;
dfs(v, x, h1 ^ e[i].v1, h2 ^ e[i].v2);
}
}
signed main() {
read(n);
for(int i = 1; i < n; ++i) {
int u, v, w1, w2; read(u); read(v); read(w1); read(w2);
add(u, v, w1, w2);
add(v, u, w1, w2);
}
dfs(1, 0, 0, 0);
int x = 0;
for(int i = 1; i <= n; ++i) x ^= f[i] ^ d[i];
for(int i = 1; i <= n; ++i) d[i] ^= x;
std::sort(d + 1, d + n + 1);
std::sort(f + 1, f + n + 1);
for(int i = 1; i <= n; ++i)
if(f[i] != d[i]) {
puts("NO");
return 0;
}
puts("YES");
return 0;
}
Submission Info
| Submission Time |
|
| Task |
B - Tree Edges XOR |
| User |
do_while_true |
| Language |
C++ (GCC 9.2.1) |
| Score |
800 |
| Code Size |
1924 Byte |
| Status |
AC |
| Exec Time |
53 ms |
| Memory |
13928 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
800 / 800 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
01.txt, 02.txt |
| All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01.txt |
AC |
7 ms |
3556 KiB |
| 02.txt |
AC |
2 ms |
3416 KiB |
| 03.txt |
AC |
2 ms |
3452 KiB |
| 04.txt |
AC |
2 ms |
3592 KiB |
| 05.txt |
AC |
2 ms |
3560 KiB |
| 06.txt |
AC |
2 ms |
3532 KiB |
| 07.txt |
AC |
2 ms |
3444 KiB |
| 08.txt |
AC |
2 ms |
3600 KiB |
| 09.txt |
AC |
4 ms |
3596 KiB |
| 10.txt |
AC |
7 ms |
3876 KiB |
| 11.txt |
AC |
43 ms |
7700 KiB |
| 12.txt |
AC |
42 ms |
7680 KiB |
| 13.txt |
AC |
42 ms |
7728 KiB |
| 14.txt |
AC |
43 ms |
7876 KiB |
| 15.txt |
AC |
42 ms |
7836 KiB |
| 16.txt |
AC |
3 ms |
3676 KiB |
| 17.txt |
AC |
2 ms |
3452 KiB |
| 18.txt |
AC |
2 ms |
3556 KiB |
| 19.txt |
AC |
4 ms |
3572 KiB |
| 20.txt |
AC |
2 ms |
3564 KiB |
| 21.txt |
AC |
2 ms |
3568 KiB |
| 22.txt |
AC |
6 ms |
3884 KiB |
| 23.txt |
AC |
39 ms |
7908 KiB |
| 24.txt |
AC |
42 ms |
7840 KiB |
| 25.txt |
AC |
43 ms |
7848 KiB |
| 26.txt |
AC |
40 ms |
7952 KiB |
| 27.txt |
AC |
43 ms |
7724 KiB |
| 28.txt |
AC |
2 ms |
3600 KiB |
| 29.txt |
AC |
9 ms |
3832 KiB |
| 30.txt |
AC |
40 ms |
7736 KiB |
| 31.txt |
AC |
41 ms |
7848 KiB |
| 32.txt |
AC |
2 ms |
3564 KiB |
| 33.txt |
AC |
2 ms |
3472 KiB |
| 34.txt |
AC |
2 ms |
3444 KiB |
| 35.txt |
AC |
2 ms |
3560 KiB |
| 36.txt |
AC |
2 ms |
3528 KiB |
| 37.txt |
AC |
3 ms |
3532 KiB |
| 38.txt |
AC |
15 ms |
4444 KiB |
| 39.txt |
AC |
50 ms |
13568 KiB |
| 40.txt |
AC |
50 ms |
13928 KiB |
| 41.txt |
AC |
46 ms |
12524 KiB |
| 42.txt |
AC |
48 ms |
12564 KiB |
| 43.txt |
AC |
53 ms |
13860 KiB |