Submission #463445

#TimeUsernameProblemLanguageResultExecution timeMemory
463445grtPraktični (COCI18_prakticni)C++17
26 / 130
115 ms14968 KiB
#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 100 * 1000 + 10, mod = 1e9 + 7, p = 31; int n, m; vector<pi>V[nax]; int cost[nax]; bool vis[nax]; int xr[nax]; vector<pi>num; bool done[nax]; void dfs(int x, int par) { vis[x] = true; for(auto nbh : V[x]) if(nbh.ST != par) { if(!vis[nbh.ST]) { xr[nbh.ST] = xr[x] ^ cost[nbh.ND]; dfs(nbh.ST, x); } else { if(done[nbh.ND]) continue; done[nbh.ND] = true; num.emplace_back(xr[x] ^ xr[nbh.ST] ^ cost[nbh.ND], nbh.ND); } } } map<int, vi>sc; int main() {_ cin >> n >> m; for(int a, b, c, i = 1; i <= m; ++i) { cin >> a >> b >> c; V[a].emplace_back(b, i); V[b].emplace_back(a, i); cost[i] = c; } dfs(1, 0); for(int bit = 0; bit < 31; ++bit) { int hsh = 0; for(auto x : num) { hsh = ((ll)hsh * p + (((1 << bit) & x.ST) > 0)) % mod; } if(hsh != 0) sc[hsh].PB(bit); } cout << (int)sc.size() << "\n"; for(auto it : sc) { int x = 0; for(int b : it.ND) x += (1 << b); cout << x << " "; vi res = {}; for(auto el : num) { if((el.ST & x)) { res.PB(el.ND); } } cout << (int)res.size() << " "; for(int el : res) cout << el << " "; cout << "\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...