This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
graph[v].push_back(u);
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 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |