제출 #391510

#제출 시각아이디문제언어결과실행 시간메모리
391510Aldas25게임 (IOI14_game)C++14
100 / 100
531 ms25264 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef vector<int> vi; typedef long long ll; typedef vector<ll> vl; typedef pair<int, int> pii; typedef vector<pii> vii; const int MAXN = 1510; int n; int par[MAXN], sz[MAXN]; int cnt[MAXN][MAXN]; //vi nodes; int find (int a) {return par[a] = par[a]==a ? a : find(par[a]);} bool same (int a, int b) {return find(a) == find(b);} void unite (int a, int b) { a = find(a), b = find(b); if (a == b) return; if (sz[b] > sz[a]) swap(a,b); par[b] = a; sz[a] += sz[b]; FOR(i, 0, n-1) { if(same(i, a)) { cnt[i][a] = 0; cnt[i][b] = 0; cnt[a][i] = 0; cnt[b][i] = 0; } else { cnt[a][i] += cnt[b][i]; cnt[i][a] += cnt[i][b]; cnt[i][b] = 0; cnt[b][i] = 0; } } } void resetDsu () { FOR(i, 0, n-1) par[i] = i, sz[i] = 1; FOR(i, 0, n-1) FOR(j, 0, n-1) cnt[i][j] = 0; FOR(i, 0, n-1) { FOR(j, 0, n-1) if(i!=j) cnt[i][j]++; // nodes.clear(); // nodes[i].pb(i); } } void initialize(int _n) { n = _n; resetDsu(); } int hasEdge(int u, int v) { if (u > v) swap(u, v); if (same(u,v)) return 0; /*FOR(i, 0, n-1) { cout << " i = " << i << endl; FOR(j, 0, n-1) { cout << " j = " << j << " cnt[i][j] = " << cnt[i][j] << endl; } }*/ u = find(u), v = find(v); if (cnt[u][v] == 1) { unite(u,v); return 1; } cnt[u][v]--; cnt[v][u]--; return 0; } /* 4 0 1 3 0 1 2 0 2 3 1 2 3 4 0 3 2 0 0 1 1 2 1 3 2 3 4 0 3 1 0 0 2 3 1 1 2 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...