Submission #909880

#TimeUsernameProblemLanguageResultExecution timeMemory
909880nasir_bashirovEaster Eggs (info1cup17_eastereggs)C++11
0 / 100
1 ms640 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], centroid, n; void dfs(int node, int par){ dp[node] = 1; for(int i : g[node]){ if(i == par) continue; dfs(i, node); dp[node] += dp[i]; } bool f = true; int s = 0; for(int i : g[node]){ if(i == par) continue; s += dp[i]; if(dp[i] > n / 2) f = false; } if(f and n - s <= n / 2) centroid = node; } bool del(int node, int spec){ used[node] = true; 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; } for(pii i : bridges){ g[i.first].push_back(i.second); g[i.second].push_back(i.first); } dfs(1, 1); int cur = centroid, par = cur; while(true){ 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); cur = nxt; } return -1; }

Compilation message (stderr)

eastereggs.cpp: In function 'bool del(int, int)':
eastereggs.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:72:25: warning: unused variable 'par' [-Wunused-variable]
   72 |     int cur = centroid, par = cur;
      |                         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...