제출 #581391

#제출 시각아이디문제언어결과실행 시간메모리
581391jasmin게임 (IOI14_game)C++17
100 / 100
460 ms24656 KiB
#include<bits/stdc++.h> #include<game.h> using namespace std; #define int long long vector<int> chef; vector<int> s; vector<vector<int> > con; int n; int find(int a){ if(chef[a]==a) return a; return chef[a]=find(chef[a]); } void unite(int a, int b){ assert(find(a)!=find(b)); s[find(a)]+=s[find(b)]; for(int i=0; i<n; i++){ if(find(i)!=i) continue; con[find(i)][find(a)]+=con[find(i)][find(b)]; } for(int i=0; i<n; i++){ if(find(i)!=i) continue; con[find(a)][find(i)]+=con[find(b)][find(i)]; } chef[find(b)]=find(a); } void initialize(int32_t a){ n=a; chef.assign(n, 0); iota(chef.begin(), chef.end(), 0); s.assign(n, 1); con.assign(n, vector<int> (n, 0)); } int32_t hasEdge(int32_t u, int32_t v){ assert(find(u)!=find(v)); con[find(u)][find(v)]++; con[find(v)][find(u)]++; //cout << con[find(u)][find(v)] << " " << s[find(u)] << " " << s[find(v)] << "\n"; if(con[find(u)][find(v)]==s[find(u)]*s[find(v)]){ unite(u, v); return 1; } return 0; } /*signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; initialize(n); for(int i=0; i<(n*(n-1))/2; i++){ int a, b; cin >> a >> b; cout << hasEdge(a, b) << "\n" << flush; for(int i=0; i<n; i++){ cout << i << " " << find(i) << "\n"; for(int j=0; j<n; j++){ cout << j << " " << find(j) << " " << con[find(i)][find(j)] << "\n"; } } cout << "hallo\n" << flush; } }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...