Submission #230618

#TimeUsernameProblemLanguageResultExecution timeMemory
230618VEGAnnPraktični (COCI18_prakticni)C++14
130 / 130
145 ms14720 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 = 30; vector<int> extra, vec[PW]; vector<pii> g[N], vc; int U[N], V[N], C[N], pre[N], xr[N], tt = 0; int XOR = -1, n, m, basis[PW], siz = 0, id[PW], obr[PW]; 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){ for (pii u : g[v]){ if (u.ft == p) continue; xr[u.ft] = (xr[v] ^ u.sd); dfs(u.ft, v); } } void insert_to_basis(int x){ for (int po = 0; po < PW; po++){ if (!(x & (1 << po))) continue; if (basis[po] == 0) { basis[po] = x; id[po] = siz; obr[siz] = po; siz++; return; } else x ^= basis[po]; } } void add(pii x){ for (int po = 0; po < PW; po++){ if (!(x.sd & (1 << po))) continue; assert(basis[po] != 0); vec[id[po]].PB(x.ft); x.sd ^= basis[po]; } } 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]--; } for (int i = m - 1; i >= 0; 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)); insert_to_basis(cxr); } } if (!sz(vc)) cout << 0; else { cout << siz << '\n'; for (pii cr : vc) add(cr); for (int i = 0; i < siz; i++){ cout << basis[obr[i]] << " " << sz(vec[i]); for (int cr : vec[i]) cout << " " << cr + 1; 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...