Submission #230503

#TimeUsernameProblemLanguageResultExecution timeMemory
230503VEGAnnPraktični (COCI18_prakticni)C++14
0 / 130
136 ms17780 KiB
#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<pair<int, vector<int> > > result; vector<int> extra, ids; vector<pii> 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 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) vc.PB(MP(nm, cxr)); } if (sz(vc) == 0) cout << 0; else { for (int bt = 0; bt < 30; bt++){ int ost = -1; ids.clear(); for (pii cr : vc) if (cr.sd & (1 << bt)){ ids.PB(cr.ft); if (ost < 0) ost = cr.sd; else ost &= cr.sd; } if (ost < 0) continue; result.PB(MP(ost, ids)); for (pii &cr : vc) if (cr.sd & (1 << bt)) cr.sd ^= ost; } cout << sz(result) << '\n'; for (pair<int, vector<int> > cr : result){ cout << cr.ft << " " << sz(cr.sd); for (int vls : cr.sd) cout << " " << vls; cout << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...