# Need help with this problem

https://codeforces.com/gym/102279/problem/G
here is my solution failing on 15th testcase

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector
#define vll vector
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define int ll
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1; while(k<=x) {if(x&k){ans=((ansa)%m);} k<<=1; a=a; a%=m; }return ans; }
pair<int,int>bfs(map<int,vector>l,int src){
int n = l.size();
bool visited[n];
int distance[n]={0};
int pt;
for(int i=0;i<n;i++){
visited[i] = false;
}
queueq;
q.push(src);
// int cnt=0;
distance[src]=1;
//cout<<src<<"\n";
visited[src] = true;
//int temp;
while(!q.empty()){
int node = q.front();
q.pop();
// cnt++;

``````for(auto x:l[node]){
if(!visited[x]){
visited[x] = true;
q.push(x);
pt= x;
distance[x] = distance[node]+1;
//temp = cnt;
}
}
``````

}
pair<int,int>p;
p.F = pt;
//cout<<distance[6]<<“sd”<<"\n";
p.S = *max_element(distance,distance+n);
//cout<<cnt<<"\n";
return p;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“a.txt”, “w”, stdout);
#endif
int n;
cin>>n;
map<int,vector>l;
int k=n-1;
int pt;
while(k–){
int a,b;
cin>>a>>b;
a–,b–;
l[a].pb(b);
l[b].pb(a);
pt=a;
}
pair<int,int>p =bfs(l,pt);
// cout<<p.F<<" “<<p.S<<”\n";
p = bfs(l,p.F);
//cout<<p.S<<"\n";
int tmp = p.S;

``````//int degree[n+1];
int m;
cin>>m;
k=m-1;
map<int,vector<int>>lp;
while(k--){
int a,b;
cin>>a>>b;
a--,b--;
lp[a].pb(b);
lp[b].pb(a);
pt=a;
}

pair<int,int>pe =bfs(lp,pt);
//cout<<pe.F<<" "<<pe.S<<"\n";
pe = bfs(lp,p.F);
int ke = pe.S;
int mx = ceil((double)ke/2);
if(tmp>mx){
cout<<"GGEZ"<<"\n";
}else{
cout<<"FF"<<"\n";
}
``````

return 0;
}

2 Likes