This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define pis pair<int,short>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int oo = 2e9;
const int N = 100100;
const int PW = 20;
vector<int> extra, vc;
vector<pii> g[N];
int U[N], V[N], C[N], pre[N], pr[N][PW], xr[N], tt = 0, tin[N], tout[N];
int XOR = -1, n, m;
bool cmp(int _x, int _y){
return C[_x] < C[_y];
}
int get(int x) { return (pre[x] == x ? x : pre[x] = get(pre[x])); }
void dfs(int v, int p){
tin[v] = tt++;
pr[v][0] = p;
for (int po = 1; po < PW; po++)
pr[v][po] = pr[v][pr[v][po - 1]];
for (pii u : g[v]){
if (u.ft == p) continue;
xr[u.ft] = (xr[v] ^ u.sd);
dfs(u.ft, v);
}
tout[v] = tt++;
}
bool upper(int a, int b){
return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}
int lca(int a, int b){
if (upper(a, b)) return a;
if (upper(b, a)) return b;
for (int po = PW - 1; po >= 0; po--)
if (!upper(pr[a][po], b))
a = pr[a][po];
return pr[a][0];
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
for (int i = 0; i < n; i++)
pre[i] = i;
for (int i = 0; i < m; i++){
cin >> U[i] >> V[i] >> C[i];
U[i]--; V[i]--;
int x = get(U[i]), y = get(V[i]);
if (x == y) {
extra.PB(i);
} else {
pre[x] = y;
g[U[i]].PB(MP(V[i], C[i]));
g[V[i]].PB(MP(U[i], C[i]));
}
}
dfs(0, 0);
for (int nm : extra){
int x = U[nm], y = V[nm];
int cxr = (xr[x] ^ xr[y] ^ C[nm]);
if (cxr != 0){
if (XOR < 0)
XOR = cxr;
if (XOR != cxr){
while (1) {}
}
vc.PB(nm);
}
}
if (XOR < 0)
cout << 0;
else {
cout << "1\n" << XOR << " " << sz(vc);
for (int id : vc)
cout << " " << id + 1;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |