제출 #348382

#제출 시각아이디문제언어결과실행 시간메모리
348382iliccmarko게임 (IOI14_game)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define INF 1000000000 #define LINF 1000000000000000LL #define pb push_back #define all(x) x.begin(), x.end() #define len(s) (int)s.size() #define test_case { int t; cin>>t; while(t--)solve(); } #define single_case solve(); #define line cerr<<"----------"<<endl; #define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); } #define mod 1000000007LL int n; const int N = 1505; int parent[N], s[N]; int cnt[N][N]; int find_parent(int u) { while(u!=parent[u]) { parent[u] = parent[parent[u]]; u = parent[u]; } return u; } void _union(int u, int v) { u = find_parent(u); v = find_parent(v); if(u!=v) { if(s[u]<s[v]) swap(u, v); for(int i = 1;i<=n;i++) { cnt[i][u] += cnt[i][v]; } parent[v] = u; s[u] += s[v]; } } void initialize(int N) { n = N; for(int i = 1;i<=n;i++) parent[i] = i, s[i] = 1; } int hasEdge(int u, int v) { u++; v++; int a = find_parent(u); int b = find_parent(v); for(int i = 1;i<=n;i++) parent[i] = find_parent(i); int w = s[a]*s[b]; for(int i = 1;i<=n;i++) { w -= cnt[i][a]; } if(w==1) { cnt[u][b]++; cnt[v][a]++; _union(a, b); return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...