Submission #293133

#TimeUsernameProblemLanguageResultExecution timeMemory
293133amoo_safarSimurgh (IOI17_simurgh)C++17
13 / 100
23 ms3016 KiB
#include "simurgh.h" #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() using namespace std; typedef pair<int, int> pii; typedef long long ll; const int N = 240 + 10; vector<pii> G[N], H[N]; int mk[N], E[N], par[N], dep[N]; vector<int> R; void DFS1(int u, int d = 0){ mk[u] = 1; dep[u] = d; for(auto [adj, id] : G[u]){ if(!mk[adj]){ R.pb(id); par[adj] = u; DFS1(adj, d + 1); E[adj] = id; //cerr << "^ " << u << ' ' << adj << '\n'; } } } ll f; int mp[N]; int Ask(int rm, int is){ if(mp[rm] != -1) return mp[rm]; vector<int> R2 = R; for(auto &x : R2) if(x == rm) x = is; mp[rm] = count_common_roads(R2); //cerr << "Ask " << rm << ' ' << is << ' ' << mp[{rm, is}] << '\n'; return mp[rm]; } int sta[N * N]; vector<int> find_roads(int n, vector<int> u, vector<int> v) { vector<int> r(n - 1); int m = u.size(); for(int i = 0; i < m; i++){ G[u[i]].pb({v[i], i}); G[v[i]].pb({u[i], i}); } DFS1(0, 0); f = count_common_roads(R); E[0] = -1; par[0] = -1; //cerr << "F : " << f << '\n'; vector<int> X; for(int i = 0; i < m; i++){ if(dep[u[i]] > dep[v[i]]) swap(u[i], v[i]); if(E[v[i]] == i) continue; memset(mp, -1, sizeof mp); X.clear(); int nw = v[i]; ////cerr << '\n'; while(nw != u[i]){ ////cerr << "# " << nw << '\n'; assert(nw != 0); X.pb(E[nw]); nw = par[nw]; } //cerr << "& " << u[i] << ' ' << v[i] << '\n'; //cerr << "!! "; //cerr << x << ' '; //cerr << '\n'; int mn = f; bool flg = false; int res; //cerr << "MTF : " << f << '\n'; for(auto x : X){ if(sta[x] && flg){ if(sta[x] == 2){ mn = min(mn, res); mp[x] = res; } else { mp[x] = res + 1; mn = min(mn, res + 1); } continue; } if(sta[x] == 1){ mn = min(mn, Ask(x, i)); res = Ask(x, i) - 1; flg = true; } else if(sta[x] == 2){ mn = min(mn, Ask(x, i)); res = Ask(x, i); flg = true; } else { mn = min(mn, Ask(x, i)); } } //cerr << "mn : " << mn << '\n'; bool f2 = (f != mn); for(auto x : X) if(mn != Ask(x, i)) f2 = true; if(f2){ if(f == mn) sta[i] = 2; else sta[i] = 1; for(auto x : X){ if(sta[x] == 0){ if(Ask(x, i) == mn) sta[x] = 2; else sta[x] = 1; } } } else { sta[i] = 1; for(auto x : X) sta[x] = 1; } //for(int j = 0; j < m; j++) //cerr << sta[j]; //cerr << '\n'; } vector<int> res; for(int i = 0; i < m; i++) if(sta[i] != 1) res.pb(i); //for(auto x : res) //cerr << "% " << x << '\n'; assert(((int) res.size()) == n - 1); return res; }
#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...