답안 #762153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762153 2023-06-21T01:52:00 Z maomao90 Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
400 ms 131072 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

#define REP(i, j, k) for (int i = (j); i < (k); i++)
#define RREP(i, j, k) for (int i = (j); i >= (k); i--)

template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 600;

int n;
vi adj[MAXN];
bool guilty[MAXN], vis[MAXN];

int findEgg (int N, vii bridges) {
	n = N;
	REP (i, 0, n - 1) {
		auto [u, v] = bridges[i];
		adj[u].pb(v);
		adj[v].pb(u);
	}
	REP (i, 1, n + 1) {
		guilty[i] = 1;
	}
	while (1) {
		queue<int> bfs;
		bfs.push(1);
		int all = 0;
		REP (i, 1, n + 1) {
			all += guilty[i];
		}
		if (all == 1) {
			break;
		}
		int cnt = 0;
		memset(vis, 0, sizeof vis);
		while (!bfs.empty()) {
			int u = bfs.front(); bfs.pop();
			vis[u] = 1;
			cnt += guilty[u];
			if (cnt >= all / 2) {
				break;
			}
			for (int v : adj[u]) {
				if (vis[v]) {
					continue;
				}
				bfs.push(v);
			}
		}
		vi qry;
		cerr << "QUERY: ";
		REP (i, 1, n + 1) {
			if (vis[i]) {
				qry.pb(i);
				cerr << i << ' ';
			}
		}
		cerr << '\n';
		bool res = query(qry);
		cerr << "RETURN: " << res << '\n';
		REP (i, 1, n + 1) {
			if (guilty[i]) {
				guilty[i] ^= res ^ vis[i];
			}
		}
	}
	REP (i, 1, n + 1) {
		if (guilty[i]) {
			return i;
		}
	}
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, vii)':
eastereggs.cpp:98:1: warning: control reaches end of non-void function [-Wreturn-type]
   98 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 437 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 453 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 503 ms 131072 KB Time limit exceeded
2 Halted 0 ms 0 KB -