Submission #1043695

#TimeUsernameProblemLanguageResultExecution timeMemory
1043695Mr_HusanboySimurgh (IOI17_simurgh)C++17
0 / 100
0 ms428 KiB
#include "simurgh.h" #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(a) (a).begin(), (a).end() #define ll long long template<typename T> int len(T &a){ return a.size(); } struct DSU{ vector<int> par, sz; int n; DSU (int _n){ n = _n; par.resize(n); iota(all(par), 0); sz.assign(n, 1); } DSU (){} int get(int a){ return (par[a] == a ? a : par[a] = get(par[a])); } void init(int _n){ n = _n; par.resize(n); iota(all(par), 0); sz.assign(n, 1); } void unite(int a, int b){ a = get(a); b = get(b); if(a == b) return; if(sz[a] < sz[b]) swap(a,b); sz[a] += sz[b]; par[b] = a; } void link(int a, int b){ a = get(a); b = get(b); if(a == b) return; sz[b] += sz[a]; par[a] = b; } }; vector<int> find_roads(int n, vector<int> u, vector<int> v) { vector<int> royal; int m = len(u); vector<int> done(m); DSU roy(n); for(int i = 0; i < n - 1; i ++){ DSU t(n); vector<int> gs; vector<int> rem; for(int j = 0; j < m; j ++){ if(u[j] == i || v[j] == i){ rem.push_back(j); }else{ if(t.get(v[j]) == t.get(u[j])) continue; gs.push_back(j); t.unite(v[j], u[j]); } } vector<vector<int>> mp; map<int,int> id; for(auto j : rem){ //cout<<j << ' '; int p = t.get(u[j] ^ v[j] ^ i); if(id.count(p) == 0){ id[p] = len(id); mp.push_back(vector<int>()); } mp[id[p]].push_back(j); } for(int j = 0; j < len(mp); j ++){ if(len(mp[j]) == 1){ royal.push_back(mp[j][0]); roy.unite(u[mp[j][0]], v[mp[j][0]]); done[mp[j][0]] = 1; continue; }else{ for(int k = 0; k < len(mp); k ++){ if(k == j){ continue; } gs.push_back(mp[k][0]); } vector<pair<int,int>> counts; int mx = 0; for(int k = 0; k < len(mp[j]); k ++){ if(roy.get(u[mp[j][k]]) == roy.get(v[mp[j][k]])) continue; gs.push_back(mp[j][k]); int cnt = count_common_roads(gs); counts.push_back({cnt, mp[j][k]}); mx = max(mx, cnt); gs.pop_back(); } for(auto [cnt, k] : counts){ if(cnt == mx){ royal.push_back(k); roy.unite(u[k], v[k]); } } for(int k = 0; k < len(mp) - 1; k ++){ gs.pop_back(); } } }//cout << endl; } // for(auto u : royal) cout << u << ' '; // cout << endl; return royal; }
#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...