Submission #909897

#TimeUsernameProblemLanguageResultExecution timeMemory
909897nasir_bashirovEaster Eggs (info1cup17_eastereggs)C++11
10 / 100
27 ms596 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 sub[550]; vi g[550]; bool used[550]; int dp[550], w[550], centroid, n, m; void dfs(int node, int par){ dp[node] = !used[node]; for(int i : g[node]){ if(i == par or used[i]) continue; dfs(i, node); dp[node] += dp[i]; } bool f = true; int s = 0; for(int i : g[node]){ s += dp[i]; if(i == par or used[i]) continue; if(dp[i] > m / 2) f = false; } if(f and m - s <= m / 2 and !used[node]) centroid = node; } void del(int node, int spec){ used[node] = true, w[node] = 0; for(int i : g[node]){ if(i == spec or used[i]) continue; del(i, node); } } vi get(int node, int par){ vi v; v.push_back(node); for(int i : g[node]){ if(i == par or used[i]) continue; vi tmp = get(i, node); 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(), sub[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); } int cur = centroid, par = cur; while(true){ int par = -1; m = 0; for(int i = 1; i <= n; i++){ if(!used[i]) par = i, m++; } dfs(par, par); cur = centroid; // cout << par << " " << m << " " << cur << endl; int nxt = -1; for(int i : g[cur]){ if(used[i]) continue; vi v = get(i, cur); if(query(v)){ nxt = i; break; } } if(nxt == -1) return cur; del(cur, nxt); } return -1; }

Compilation message (stderr)

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:71:25: warning: unused variable 'par' [-Wunused-variable]
   71 |     int cur = centroid, par = cur;
      |                         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...