#include "game.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> cnt;
int num;
set<pair<int, int>> questions;
vector<vector<int>> connecting_edges;
vector<int> rep, sizes;
int find(int u){
if (u == rep[u]) return u;
rep[u] = find(rep[u]);
return rep[u];
}
void uni(int a, int b){
a = find(a);
b = find(b);
if (a == b) return;
if (sizes[a] < sizes[b]) swap(a, b);
rep[b] = a;
sizes[a] += sizes[b];
}
void initialize(int n) {
num = n;
connecting_edges = vector<vector<int>> (n, vector<int>(n, 1));
for (int i=0; i<n; i++) connecting_edges[i][i] = 0;
rep = sizes = vector<int>(n, 1);
iota(rep.begin(), rep.end(), 0);
}
int hasEdge(int u, int v) {
u = find(u);
v = find(v);
if (connecting_edges[u][v] > 1){
// nicht verbinden
connecting_edges[u][v]--;
connecting_edges[v][u]--;
return 0;
}
else{
// verbinden
uni(u, v);
int rep_tmp = find(u);
for (int i=0; i<num; i++) if (rep[i] == i && i != rep_tmp){
connecting_edges[rep_tmp][i] = connecting_edges[i][rep_tmp] = connecting_edges[u][i] + connecting_edges[v][i];
}
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... |