Submission #218510

#TimeUsernameProblemLanguageResultExecution timeMemory
218510quocnguyen1012Praktični (COCI18_prakticni)C++14
0 / 130
190 ms22756 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 10; vector<pair<int,int> > g[maxn]; int par[maxn], h[maxn], wg[maxn]; vector<pair<int, int> > a; vector<int> ops[maxn]; int x[maxn]; int t; void findbase(){ int n = a.size(); for (int i = 0; i <= 30; i++){ bool flag = 0; for (int j = t; j < n; j++){ if (!(a[j].first & (1 << i))) continue; swap(a[j], a[t]); flag = 1; break; } if (flag == 0) continue; x[t] = a[t].first; for (int j = t; j < n; j++){ if (a[j].first & (1 << i)){ ops[t].push_back(a[j].second); a[j].first ^= x[t]; } } t ++; } } void dfs(int v, int p = -1){ for (auto edge : g[v]){ int u = edge.first, w = wg[edge.second]; if (h[u] == -1){ h[u] = h[v] + 1; par[u] = par[v] ^ w; dfs(u, v); } if (v != p) a.push_back({par[v] ^ par[u] ^ w, edge.second}); } } int main(){ ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < m; i++){ int v, u; cin >> v >> u >> wg[i]; g[v].push_back({u, i}); g[u].push_back({v, i}); } memset(h, -1, sizeof h); h[1] = 0; dfs(1); findbase(); cout << t << endl; for (int i = 0; i < t; i++){ cout << x[i] << " "; cout << ops[i].size() << " "; sort(ops[i].begin(), ops[i].end()); for (auto it : ops[i]) cout << it + 1 << " "; cout << endl; } }
#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...