답안 #882233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882233 2023-12-02T20:23:47 Z gustavo_d Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
1 ms 476 KB
// https://oj.uz/problem/view/info1cup17_eastereggs > p150
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int findEgg (int N, vector < pair < int, int > > bridges)
{
	vector<vector<int>> adj(N);
	vector<bool> vis(N, false);
	vector<int> always;
	for (pair<int,int> p : bridges) {
		adj[p.first-1].push_back(p.second-1);
		adj[p.second-1].push_back(p.first-1);
	}
	queue<int> visit; visit.push(0); vis[0] = true;
	vector<int> send;
	int n = N;
	while (!visit.empty()) {
		int v = visit.front();
		visit.pop();
		send.push_back(v+1);
		
		for (int viz : adj[v]) {
			if (!vis[viz]) {
				vis[viz] = true;
				visit.push(viz);
			}
		}		
		
		if ((int)send.size() == (n+1)/2) {
			for (int i : send) always.push_back(i);
			int res = query(always);
			//for (int i : always) cout << i << ' ';
			//cout << send.size() << ' ' << res << endl;
			if ((int)send.size() == 1 and res == 1) {
				return send[0];
			}
			if (res == 0) {
				n -= (int)send.size();
			}
			else {
				for (int i=0; i<(int)send.size(); i++) always.pop_back();
				n = (int)send.size();
				for (int i=0; i<N; i++) vis[i] = true;
				while (!visit.empty()) visit.pop();
				for (int i : send) {
					vis[i] = false;
				}
				for (int i : always) {
					visit.push(i);
					vis[i] = true;
				}
				if (visit.empty()) {
					visit.push(0);
					vis[0] = true;
				}
			}
			send.clear();
		}
	}
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 436 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 456 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 476 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -