This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** * * * * * * * * * * * * * **\
* *
* Author: Haidara Nassour *
* Coded in: YYYY\M\D HH:MM:SS *
* Lang: C++ *
* *
\** * * * * * * * * * * * * * **/
#include<bits/stdc++.h>
#include<grader.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define int long long
#define itn int
#define rep(i,x,n) for(int i=(x);i<(n);i++)
#define FOR(i,n) rep(i,0,n)
#define per(i,x,n) for(int i=(x);i>(n);i--)
#define ROF(i,x) for(int i=x;i>=0;i--)
#define v(i) vector< i >
#define p(i,j) pair< i , j >
#define pii pair<int,int>
#define m(i,j) map< i , j >
#define um(i,j) unordered_map< i , j >
#define max_heap(i) priority_queue< i >
#define min_heap(i) priority_queue< i , vector< i > ,greater< i > >
#define ff first
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ss second
#define pp push_back
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
#define debug(x) cout<<#x<<" ";
using namespace std;
using namespace __gnu_pbds;
void SIO(string name="")
{
if(name!="")
{
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
}
template <class T> using o_set = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
///order_of_key = find index of element x ( returned val is integer )
///find_by_order = find value at index x ( returned val is pointer )
const double pi=2.0*acos(0.0);
const int inf=1LL<<60LL;
const int mod=1e9+7;
const int maxn=555;
set<int>graph[maxn];
int dp[maxn];
set<int>s[maxn];
int n;
void dfs(int st=1,int par=-1)
{
dp[st]=1;
s[st].insert(st);
for(auto i:graph[st])
{
if(i==par)
continue;
dfs(i,st);
dp[st]+=dp[i];
s[st].insert(all(s[i]));
}
}
int find_centroid(int st)
{
for(auto i:graph[st])
if(dp[i]>n/2)
{
dp[st]-=dp[i];
dp[i]=n;
for(auto j:s[i])
s[st].erase(j);
s[i].insert(all(s[st]));
return find_centroid(i);
}
return st;
}
int findEgg(int N,v(pii)edges)
{
n=N;
for(auto i:edges)
{
graph[i.ff].insert(i.ss);
graph[i.ss].insert(i.ff);
}
dfs();
int sz=n,st=1;
while(sz-1)
{
st=find_centroid(st);
v(int)nodes;
int mx=0,node;
for(auto i:graph[st])
if(dp[i]>mx)
mx=dp[i],node=i;
for(auto i:graph[st])
if(i==node)
continue;
else
for(auto j:s[i])
nodes.pp(j);
if(query(nodes))
{
sz=dp[st]-dp[node];
dp[st]-=dp[node];
for(auto i:s[node])
s[st].erase(i),graph[st].erase(i);
}
else
{
sz=dp[node];
graph[node].erase(st);
st=node;
}
}
return st;
}
Compilation message (stderr)
eastereggs.cpp:48:18: warning: overflow in conversion from 'long long int' to 'int' changes value from '1152921504606846976' to '0' [-Woverflow]
48 | const int inf=1LL<<60LL;
| ~~~^~~~~~
eastereggs.cpp: In function 'void SIO(std::string)':
eastereggs.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
eastereggs.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:108:30: warning: 'node' may be used uninitialized in this function [-Wmaybe-uninitialized]
108 | sz=dp[st]-dp[node];
| ~~~~~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |