이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstdlib>
#include <string>
#include "grader.h"
using namespace std;
int curTime = 1, possibleChecks, maxChecks, possibleCnt;
vector<bool> visited, possible, checked;
vector<int> checks;
vector< vector<int> > graph;
void dfs(int u)
{
if (possibleChecks >= maxChecks) return;
if (visited[u]) return;
visited[u] = 1;
if (possible[u]) {
++possibleChecks;
}
checks.push_back(u);
checked[u] = 1;
for (int v : graph[u]) dfs(v);
}
int findEgg(int N, vector< pair<int, int> > bridges)
{
graph.resize(N+1);
for (auto a : bridges) {
int u = a.first, v = a.second;
if (u > v) graph[v].push_back(u);
else graph[u].push_back(v);
}
possibleCnt = N;
possible.assign(N+1, 1);
while (true) {
if (possibleCnt == 1) {
for (int u = 1; u <= N; ++u) {
if (possible[u]) return u;
}
}
possibleChecks = 0;
maxChecks = possibleCnt / 2;
visited.assign(N+1, 0);
checked.assign(N+1, 0);
checks.clear();
dfs(1);
int q = query(checks);
if (q == 0) {
possibleCnt = 0;
for (int u = 1; u <= N; ++u) {
if (checked[u]) {
possible[u] = 0;
} else {
if (possible[u]) ++possibleCnt;
}
}
} else {
possibleCnt = 0;
for (int u = 1; u <= N; ++u) {
if (!checked[u]) {
possible[u] = 0;
} else {
if (possible[u]) ++possibleCnt;
}
}
}
}
return 8713409;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |