제출 #347341

#제출 시각아이디문제언어결과실행 시간메모리
347341ogibogi2004게임 (IOI14_game)C++14
100 / 100
627 ms34356 KiB
#include "game.h" #include<bits/stdc++.h> using namespace std; const int MAXN=1502; int cnte[MAXN][MAXN]; int par[MAXN],n1; int asked[MAXN][MAXN]; void join(int p,int q) { for(int i=0;i<n1;i++) { if(par[i]==q)par[i]=p; } for(int i=0;i<n1;i++) { if(p==i)continue; cnte[i][p]+=cnte[i][q]; cnte[p][i]=cnte[i][p]; } } void initialize(int n) { n1=n; for(int i=0;i<n;i++) { par[i]=i; for(int j=0;j<n;j++) { if(i!=j)cnte[i][j]=1; } } } int hasEdge(int u, int v) { /*for(int i=1;i<=n1;i++) { for(int j=1;j<=n1;j++) { cout<<cnte[i][j]<<" "; } cout<<endl; }*/ if(asked[u][v]!=0) { return (asked[u][v]+1)/2; } int p=par[u],q=par[v]; if(p==q) { asked[u][v]=1; asked[v][u]=1; return 1; } if(cnte[p][q]==1) { asked[u][v]=1; asked[v][u]=1; join(p,q); return 1; } else { cnte[q][p]--; cnte[p][q]--; asked[u][v]=-1; asked[v][u]=-1; return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...