Submission #58161

#TimeUsernameProblemLanguageResultExecution timeMemory
58161qkxwsmGame (IOI14_game)C++17
100 / 100
944 ms16336 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; template<class T> void readi(T &x) { T input = 0; bool negative = false; char c = ' '; while (c < '-') { c = getchar(); } if (c == '-') { negative = true; c = getchar(); } while (c >= '0') { input = input * 10 + (c - '0'); c = getchar(); } if (negative) { input = -input; } x = input; } template<class T> void printi(T output) { if (output == 0) { putchar('0'); return; } if (output < 0) { putchar('-'); output = -output; } int aout[20]; int ilen = 0; while(output) { aout[ilen] = ((output % 10)); output /= 10; ilen++; } for (int i = ilen - 1; i >= 0; i--) { putchar(aout[i] + '0'); } return; } template<class T> void ckmin(T &a, T b) { a = min(a, b); } template<class T> void ckmax(T &a, T b) { a = max(a, b); } long long randomize(long long mod) { return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod; } #define MP make_pair #define PB push_back #define PF push_front #define LB lower_bound #define UB upper_bound #define fi first #define se second const long double PI = 4.0 * atan(1.0); const long double EPS = 1e-20; #define MAGIC 347 #define SINF 10007 #define CO 1000007 #define INF 1000000007 #define BIG 1000000931 #define LARGE 1696969696967ll #define GIANT 2564008813937411ll #define LLINF 2696969696969696969ll #define MAXN 1513 long long normalize(long long x, long long mod = INF) { return (((x % mod) + mod) % mod); } typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int N; int cnt[MAXN]; int dsu[MAXN]; int sz[MAXN]; int ask[MAXN][MAXN]; void initialize(int n) { N = n; for (int i = 0; i < N; i++) { dsu[i] = i; sz[i] = 1; } } int find_parent(int u) { if (u == dsu[u]) { return dsu[u]; } dsu[u] = find_parent(dsu[u]); return dsu[u]; } void merge(int u, int v) { u = find_parent(u); v = find_parent(v); if (u == v) { return; } if (sz[u] > sz[v]) { swap(u, v); } dsu[u] = v; sz[v] += sz[u]; for (int i = 0; i < N; i++) { if (u == i || v == i) { continue; } ask[v][i] += ask[u][i]; ask[i][v] = ask[v][i]; } ask[v][v] = 0; return; } int hasEdge(int u, int v) { int res = 0; u = find_parent(u); v = find_parent(v); ask[u][v]++; ask[v][u]++; if (ask[u][v] == sz[u] * sz[v]) { res = 1; merge(u, v); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...