Submission #63520923
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXE = 4e5 + 10;
struct edge
{
int to, z, nxt;
};
edge ed[MAXE];
int head[MAXN], tot;
int dval[MAXN];
bool vis[MAXN];
long long ans[MAXN];
int stk[MAXN], comp[MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
head[i] = -1;
vis[i] = false;
}
tot = 0;
for (int i = 0; i < m; i++)
{
int u, v, z;
cin >> u >> v >> z;
ed[tot].to = v;
ed[tot].z = z;
ed[tot].nxt = head[u];
head[u] = tot++;
ed[tot].to = u;
ed[tot].z = z;
ed[tot].nxt = head[v];
head[v] = tot++;
}
for (int i = 1; i <= n; i++)
{
if (!vis[i])
{
int top = 0, cmpsize = 0;
stk[top++] = i;
vis[i] = true;
dval[i] = 0;
while (top)
{
int u = stk[--top];
comp[cmpsize++] = u;
for (int j = head[u]; j != -1; j = ed[j].nxt)
{
int v = ed[j].to;
if (!vis[v])
{
vis[v] = true;
dval[v] = dval[u] ^ ed[j].z;
stk[top++] = v;
}
else if ((dval[u] ^ dval[v]) != ed[j].z)
{
cout << -1;
return 0;
}
}
}
int t_val = 0;
for (int b = 0; b < 31; b++)
{
int mask = (1 << b);
int cnt1 = 0;
for (int j = 0; j < cmpsize; j++)
{
if (dval[comp[j]] & mask)
cnt1++;
}
if (cnt1 > cmpsize - cnt1)
t_val |= mask;
}
for (int j = 0; j < cmpsize; j++)
{
int u = comp[j];
ans[u] = dval[u] ^ t_val;
}
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Min of Restricted Sum |
| User | mywwzh |
| Language | C++ 20 (gcc 12.2) |
| Score | 450 |
| Code Size | 2353 Byte |
| Status | AC |
| Exec Time | 43 ms |
| Memory | 9224 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3496 KiB |
| 00_sample_01.txt | AC | 1 ms | 3480 KiB |
| 00_sample_02.txt | AC | 1 ms | 3412 KiB |
| 01_handmade_00.txt | AC | 1 ms | 3480 KiB |
| 01_handmade_01.txt | AC | 17 ms | 6852 KiB |
| 01_handmade_02.txt | AC | 1 ms | 3488 KiB |
| 01_handmade_03.txt | AC | 1 ms | 4588 KiB |
| 01_handmade_04.txt | AC | 1 ms | 3540 KiB |
| 01_handmade_05.txt | AC | 1 ms | 4588 KiB |
| 01_handmade_06.txt | AC | 17 ms | 6772 KiB |
| 01_handmade_07.txt | AC | 39 ms | 9092 KiB |
| 01_handmade_08.txt | AC | 35 ms | 9200 KiB |
| 01_handmade_09.txt | AC | 21 ms | 5844 KiB |
| 02_random_00.txt | AC | 25 ms | 7144 KiB |
| 02_random_01.txt | AC | 33 ms | 8120 KiB |
| 02_random_02.txt | AC | 38 ms | 8712 KiB |
| 02_random_03.txt | AC | 43 ms | 9224 KiB |
| 02_random_04.txt | AC | 20 ms | 6816 KiB |
| 02_random_05.txt | AC | 34 ms | 8168 KiB |
| 02_random_06.txt | AC | 30 ms | 7864 KiB |
| 02_random_07.txt | AC | 43 ms | 9160 KiB |
| 02_random_08.txt | AC | 23 ms | 6864 KiB |
| 02_random_09.txt | AC | 27 ms | 7404 KiB |
| 02_random_10.txt | AC | 14 ms | 5852 KiB |
| 02_random_11.txt | AC | 27 ms | 7644 KiB |
| 02_random_12.txt | AC | 16 ms | 6184 KiB |
| 02_random_13.txt | AC | 19 ms | 9112 KiB |
| 02_random_14.txt | AC | 11 ms | 5612 KiB |
| 02_random_15.txt | AC | 17 ms | 8408 KiB |
| 02_random_16.txt | AC | 15 ms | 6248 KiB |
| 02_random_17.txt | AC | 20 ms | 9068 KiB |
| 02_random_18.txt | AC | 22 ms | 7004 KiB |
| 02_random_19.txt | AC | 42 ms | 8988 KiB |
| 02_random_20.txt | AC | 6 ms | 4256 KiB |
| 02_random_21.txt | AC | 31 ms | 7844 KiB |
| 02_random_22.txt | AC | 18 ms | 6236 KiB |
| 02_random_23.txt | AC | 29 ms | 7944 KiB |
| 02_random_24.txt | AC | 20 ms | 5756 KiB |