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 <bits/stdc++.h>
#include "game.h"
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
int used[1005]; //group number
int live, comp, cnt[1005];
int query[1005][1005]; // 0 - not queried; 1 - no; 2 - yes
int n ;
void initialize(int N) {
n = N;
return;
}
int hasEdge(int u, int v) {
if (used[u] && used[v]) {
int total = 0;
FOR(i, 1, n) {
if (used[i] == used[u]) {
FOR(j, 1, n) {
if (used[i] != used[j] && used[j] > 0 && query[i][j] == 0) total++;
}
}
}
if (total == 1) {
query[u][v] = query[v][u] = 2;
return 1;
}
total = 0;
FOR(i, 1, n) {
if (used[i] == used[v]) {
FOR(j, 1, n) {
if (used[i] != used[j] && used[j] > 0 && query[i][j] == 0) total++;
}
}
}
if (total == 1) {
query[u][v] = query[v][u] = 2;
return 1;
}
query[u][v] = query[v][u] = 1;
return 0;
}
if (!used[u] && !used[v]) {
comp++;
used[u] = used[v] = comp;
query[u][v] = query[v][u] = 2;
live += 2;
return 1;
}
if (used[v]) swap(u, v);
cnt[v]++;
if (cnt[v] == live) {
live++;
used[v] = used[u];
query[u][v] = query[v][u] = 2;
return 1;
}
query[u][v] = query[v][u] = 1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |