Submission #776762

#TimeUsernameProblemLanguageResultExecution timeMemory
776762vjudge1Praktični (COCI18_prakticni)C++17
130 / 130
86 ms20940 KiB
#include <bits/stdc++.h> using namespace std; #define sp " " #define endl "\n" #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define N 200005 #define LOGN 30 vector<array<int, 3>> adj[N]; int dist[N], vis[N], mark[N], val[N], base[N]; void dfs(int node, int root, int d){ dist[node] = d; vis[node] = 1; for (auto i : adj[node]){ int curr = i[0], w = i[1], ind = i[2]; if (curr == root) continue; if (vis[curr]){ mark[ind] = 1; val[ind] = w ^ dist[curr] ^ dist[node]; } else{ dfs(curr, node, d ^ w); } } } int32_t main(){ #ifndef ONLINE_JUDGE //fileio(); #endif fastio(); int n, m; cin>>n>>m; for (int i = 1; i <= m; i++){ int u, v, w; cin>>u>>v>>w; adj[u].pb({v, w, i}); adj[v].pb({u, w, i}); } dfs(1, 0, 0); for (int i = 1; i <= m; i++){ if (mark[i]){ int x = val[i]; for (int j = LOGN; j >= 0; j--){ if (x & (1<<j)){ if (base[j] != 0){ x ^= base[j]; } else{ base[j] = x; break; } } } } } vector<int> ans[LOGN + 1]; for (int i = 1; i <= m; i++){ if (mark[i]){ int x = val[i]; for (int j = LOGN; j >= 0; j--){ if (x & (1<<j)){ ans[j].pb(i); x ^= base[j]; } } } } int res = 0; for (int i = LOGN; i >= 0; i--){ if (ans[i].size()) res++; } cout<<res<<endl; for (int i = LOGN; i >= 0; i--){ if (ans[i].size()){ cout<<base[i]<<sp<<ans[i].size()<<sp; for (auto j : ans[i]) cout<<j<<sp; cout<<endl; } } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#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...