답안 #269764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
269764 2020-08-17T09:52:17 Z Fasho Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
7 ms 5376 KB
#include <bits/stdc++.h>
#define NNN 100005
#define ll long long int
#define fo(i,x,y)	for(int i=x;i<=y;i++)
#define fs(ar,n) fo(i,1,n) cin>>ar[i]
#define sp " "
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll> 
#include "grader.h"
using namespace std;

ll n,m,ar[NNN],sum,t,mark[NNN];

queue<int> q;

vector<int> vv[NNN];

bool check(int x)
{
	vector<int> bos;
	fo(i,1,x)
		bos.pb(ar[i]);
	return query(bos);
}

int bs()
{
	int l=1,r=n;
	while(l<r)
	{
		if(l==r-1)
		{
			if(check(l))
				r=l;
			break;
		}
		int mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	return r;
}

int findEgg (int NN, vector < pair < int, int > > bridges)
{
	n=NN;
	q.push(1);
	ll cnt=0;
	
	fo(i,0,n-2)
	{
		ll a=bridges[i].fi;
		ll b=bridges[i].se;
		vv[a].pb(b);
		vv[b].pb(a);
	}

	while(q.size())
	{
		ll x=q.front();
		q.pop();
		if(mark[x])
			continue;
		mark[x]=++cnt;
		ar[cnt]=x;
		for(int i=0;i<vv[x].size();i++)
		{
			ll y=vv[x][i];
			if(mark[y])
				continue;
			q.push(y);
		}
	}
	// fo(i,1,n)
	// cout<<ar[i]<<sp;
	// 	cout<<endl;
	// bs();
    return bs();
}


// int main ()
// {
// // freopen ("input", "r", stdin);
// //freopen ("output", "w", stdout);

// scanf ("%d", &N);
// // int Queries;
// vector < pair < int, int > > param;
// for (int i=1; i<N; i++)
// {
//     int x, y;
//     scanf ("%d %d", &x, &y);
//     v[x].push_back (y);
//     v[y].push_back (x);
//     param.push_back ({x, y});
// }
// // scanf ("%d", &Queries);
// // while (Queries --)
// // {
// //     scanf ("%d", &X), cntQ = 0;
//     int Y = findEgg (N, param);
// //     if (X != Y)
// //     {
// //         printf ("WA %d instead of %d\n", Y, X);
// //         return 0;
// //     }
// //     printf ("OK %d\n", cntQ);
// // }
// // return 0;
// }

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for(int i=0;i<vv[x].size();i++)
      |               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5292 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -