Submission #414512

#TimeUsernameProblemLanguageResultExecution timeMemory
414512illyakrGame (IOI14_game)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; int pred[1510]; int step[1510]; int find(int v) { if (pred[v] == v)return v; return pred[v] = find(pred[v]); } void make(int v, int n) { pred[v] = v; step[v] = n - 1; return; } void merge(int a, int b) { a = find(a); b = find(b); if (a == b)return; step[a] += step[b]; pred[b] = a; } int was[1510][1510]; int N; void initialize(int n) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { was[i][j] = -1; } was[i][i] = 0; } for (int i = 1; i <= n; i++) make(i, n); N = n; } int hasEdge(int u, int v) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (was[i][j] != -1)continue; if (find(i) != find(j))continue; was[i][j] = 0; was[j][i] = 0; step[find(i)] -= 2; } } u++; v++; if (was[u][v] != -1) return was[u][v]; if (step[find(u)] == 0 || step[find(v)] == 0)exit(1); if (step[find(u)] <= 1 || step[find(v)] <= 1) { was[u][v] = 1; was[v][u] = 1; merge(u, v); step[find(u)]--; step[find(v)]--; return 1; } was[u][v] = 0; was[v][u] = 0; step[find(u)]--; step[find(v)]--; return 0; } /** 4 0 3 1 0 0 2 3 1 1 2 2 3 4 0 3 2 0 0 1 1 2 1 3 2 3 4 0 1 3 0 1 2 0 2 3 1 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...