Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4987d03

Browse files
IOI Game
1 parent c487c99 commit 4987d03

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎DMOJ/ioi14p3.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
const int MAXN = 1510;
5+
6+
static int pai[MAXN],grau[MAXN][MAXN],N;
7+
8+
int find(int x){
9+
if(x == pai[x]) return x;
10+
return pai[x] = find(pai[x]);
11+
}
12+
13+
void join(int x,int y){
14+
x = find(x);
15+
y = find(y);
16+
if(x == y) return;
17+
if(x > y) swap(x,y);
18+
pai[y] = x;
19+
for(int i = 0;i<N;i++){
20+
if(find(i) != i) continue;
21+
grau[x][i] += grau[y][i];
22+
grau[i][x] += grau[i][y];
23+
grau[y][i] = 0;
24+
grau[i][y] = 0;
25+
}
26+
}
27+
28+
void initialize(int n){
29+
30+
for(int i = 0;i<n;i++){
31+
pai[i] = i;
32+
for(int j = 0;j<n;j++) grau[i][j] = 1;
33+
grau[i][i] = 0;
34+
}
35+
N = n;
36+
37+
}
38+
39+
int hasEdge(int u, int v) {
40+
int x = find(u),y = find(v);
41+
if(x == y){
42+
return 0;
43+
}
44+
grau[x][y]--;
45+
grau[y][x]--;
46+
if(grau[x][y] == 0){
47+
join(x,y);
48+
return 1;
49+
}
50+
else{
51+
return 0;
52+
}
53+
}
54+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /