-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path59647042.cpp
50 lines (49 loc) · 939 Bytes
/
59647042.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int canopen[1001];
fill(canopen,canopen+1001,0);
int have[1001];
fill(have,have+1001,0);
int exeption[1001];
fill(exeption,exeption+1001,0);
for(int i=0;i<n;i++)
{
int a,b;
cin>>a>>b;
if(a!=b)
{
canopen[b]=1;
have[a]++;
have[b]+=exeption[b];
exeption[b]=0;
}
else
{
if(canopen[a]==1)
{
have[a]++;
have[a]+=exeption[a];
exeption[a]=0;
}
else
{
exeption[a]++;
canopen[a]=1;
}
}
}
int result=0;
for(int i=0;i<1001;i++)
{
if(canopen[i]==1)
{
result+=have[i];
}
}
cout<<n-result<<endl;
return 0;
}