답안 #882264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882264 2023-12-02T21:09:18 Z gustavo_d Easter Eggs (info1cup17_eastereggs) C++17
81 / 100
17 ms 1004 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<pair<int,int>> visit; visit.push({0, 1}); vis[0] = true;
	vector<int> send;
	int n = N;
	while (!visit.empty()) {
		int v = visit.front().first;
		if (visit.front().second == 1) send.push_back(v+1);
		visit.pop();
		
		for (int viz : adj[v]) {
			if (!vis[viz]) {
				vis[viz] = true;
				visit.push({viz, 1});
			}
		}		
		
		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 : send) 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-1] = false;
				}
				for (int i : always) {
					visit.push({i-1, -1});
				}
				if (visit.empty()) {
					visit.push({0, 1});
					vis[0] = true;
				}
			}
			send.clear();
		}
	}
	return -1;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:43:14: warning: unused variable 'i' [-Wunused-variable]
   43 |     for (int i : send) always.pop_back();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 432 KB Number of queries: 5
2 Partially correct 1 ms 440 KB Number of queries: 5
3 Partially correct 0 ms 344 KB Number of queries: 5
4 Partially correct 1 ms 440 KB Number of queries: 5
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 976 KB Number of queries: 9
2 Partially correct 10 ms 732 KB Number of queries: 10
3 Partially correct 14 ms 728 KB Number of queries: 10
4 Partially correct 14 ms 752 KB Number of queries: 10
# 결과 실행 시간 메모리 Grader output
1 Partially correct 15 ms 740 KB Number of queries: 10
2 Partially correct 13 ms 480 KB Number of queries: 10
3 Partially correct 17 ms 744 KB Number of queries: 10
4 Partially correct 15 ms 1004 KB Number of queries: 10