UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201667#3508. 朋友jane100181ms10084kbC++11496b2024-02-04 11:24:302024-02-04 12:07:08

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a,b,ans,mx;
vector<int> g[N<<1];
bool v[N<<1];
void dfs(int x){
	mx+=g[x].size();
	v[x]=1;
	for(auto i:g[x]){
		if(v[i])
			continue;
		dfs(i);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=1;i<=2*n;i++){
		if(v[i])
			continue;
		dfs(i);
		mx>>=2;
		ans+=mx;
		mx=0;
	}
	printf("%d\n",ans);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 5932kb

input:

10
19 12
8 18
6 15
4 18
15 3
8 2
6 18
18 7
18 3
8 3

output:

4

result:

ok single line: '4'

Test #2:

score: 10
Accepted
time: 0ms
memory: 5932kb

input:

10
19 16
14 8
8 12
7 10
15 5
7 10
17 7
5 4
9 6
6 12

output:

4

result:

ok single line: '4'

Test #3:

score: 10
Accepted
time: 0ms
memory: 5932kb

input:

10
7 17
11 9
18 5
11 14
10 11
7 18
11 9
4 1
3 16
8 17

output:

4

result:

ok single line: '4'

Test #4:

score: 10
Accepted
time: 0ms
memory: 5932kb

input:

20
11 1
29 27
11 34
10 27
9 10
10 21
17 18
19 14
26 14
6 26
38 30
40 11
13 7
33 9
10 32
40 28
20 21
...

output:

7

result:

ok single line: '7'

Test #5:

score: 10
Accepted
time: 0ms
memory: 5932kb

input:

20
19 21
15 9
33 10
9 15
5 32
10 21
28 19
22 11
20 4
32 10
26 8
13 27
30 7
11 22
2 35
8 14
17 28
9 3...

output:

7

result:

ok single line: '7'

Test #6:

score: 10
Accepted
time: 0ms
memory: 5932kb

input:

20
19 10
8 14
6 27
24 19
40 38
17 29
30 28
33 8
23 26
10 11
7 34
2 26
35 3
3 28
20 17
35 30
30 36
18...

output:

7

result:

ok single line: '7'

Test #7:

score: 10
Accepted
time: 44ms
memory: 10076kb

input:

100000
92387 35422
124898 132532
192988 84636
99872 57831
131700 147597
179017 125316
96560 4822
318...

output:

40939

result:

ok single line: '40939'

Test #8:

score: 10
Accepted
time: 48ms
memory: 10076kb

input:

100000
8515 151563
105451 194713
109537 130709
63343 41819
65855 51779
39457 85060
96650 174359
1936...

output:

40841

result:

ok single line: '40841'

Test #9:

score: 10
Accepted
time: 42ms
memory: 10084kb

input:

100000
91939 100407
110197 24191
58791 9486
68030 25807
11 188665
132600 12100
129445 33496
196658 1...

output:

40820

result:

ok single line: '40820'

Test #10:

score: 10
Accepted
time: 47ms
memory: 10084kb

input:

100000
30518 196518
74071 159971
150121 4862
43967 173607
19138 90754
19513 171337
183499 149873
142...

output:

40816

result:

ok single line: '40816'

Extra Test:

score: 0
Extra Test Passed