Submission #909967

#TimeUsernameProblemLanguageResultExecution timeMemory
909967nasir_bashirovEaster Eggs (info1cup17_eastereggs)C++11
0 / 100
10 ms528 KiB
#include <bits/stdc++.h> #include "grader.h" using namespace std; #define db long double #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vii vector<pii> #define vll vector<pll> #define endl '\n' #define all(x) x.begin(), x.end() #define fastio\ ios_base::sync_with_stdio(0);\ cin.tie(0);\ cout.tie(0)\ vi g[550]; bool used[550]; int dp[550], p[550], centroid, n, m; void calc_p(int node, int par){ p[node] = par; for(int i : g[node]){ if(i == par) continue; calc_p(i, node); } } void dfs(int node){ dp[node] = !used[node]; for(int i : g[node]){ dfs(i); dp[node] += dp[i]; } } int find_centr(int node){ for(int i : g[node]){ if(dp[i] >= n / 2) return find_centr(i); } return node; } void del_centr(int node){ used[node] = true; for(int i : g[node]){ del_centr(i); } } void del_noncentr(int node){ used[node] = true; for(int i : g[node]){ if(i == centroid) continue; del_noncentr(i); } } vi get(int node){ vi v; v.push_back(node); for(int i : g[node]){ if(used[i]) continue; vi tmp = get(i); if(tmp.size() > v.size()) swap(tmp, v); for(int i : tmp) v.push_back(i); } return v; } int findEgg(int N, vii bridges){ n = N; for(int i = 1; i <= n; i++){ g[i].clear(), used[i] = false, dp[i] = 0, centroid = 0; } for(pii i : bridges){ g[i.first].push_back(i.second); g[i.second].push_back(i.first); } calc_p(1, 1); for(int i = 1; i <= n; i++){ g[i].clear(), used[i] = false, dp[i] = 0, centroid = 0; } for(int i = 2; i <= n; i++){ g[p[i]].push_back(i); } while(true){ if(n == 1){ for(int i = 1; i <= N; i++){ if(!used[i]) return i; } } dfs(1); centroid = find_centr(1); if(query(get(centroid))){ n = dp[centroid]; del_noncentr(1); } else{ n -= dp[centroid]; del_centr(centroid); } } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...