-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path20170904.cpp
More file actions
109 lines (104 loc) · 1.35 KB
/
20170904.cpp
File metadata and controls
109 lines (104 loc) · 1.35 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <vector>
using namespace std;
int n, m, ans;
vector<int> v[1001];
int a[1001][1001];
void dfs(int x, int *visit, int y)
{
visit[x] = 1;
a[x][y] = a[y][x] = 1;
for (int i = 0; i < v[x].size(); i++)
{
if (visit[v[x][i]] == 0)
{
dfs(v[x][i], visit, y);
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> n >> m;
while (m--)
{
int a, b;
cin >> a >> b;
v[a].push_back(b);
}
for (int i = 1; i <= n; i++)
{
int visit[1001] = { 0 };
dfs(i, visit, i);
}
for (int i = 1; i <= n; i++)
{
int j;
for (j = 1; j <= n; j++)
{
if (a[i][j] == 0)
{
break;
}
}
if (j == n + 1)
{
ans++;
}
}
cout << ans << endl;
return 0;
}
//#include <iostream>
//
//using namespace std;
//
//int pre[1001], n, m, a, b, ans;
//
//void init()
//{
// for (int i = 1; i <= n; i++)
// {
// pre[i] = i;
// }
//}
//
//int find(int x)
//{
// if (x == pre[x])
// {
// return x;
// }
// return pre[x] = find(pre[x]);
//}
//
//void join(int x, int y)
//{
// int x1 = find(x);
// int y1 = find(y);
// if (x1 != y1)
// {
// pre[y1] = x1;
// }
//}
//
//int main()
//{
// std::ios::sync_with_stdio(false);
// cin >> n >> m;
// init();
// while (m--)
// {
// cin >> a >> b;
// join(a, b);
// }
// for (int i = 1; i <= n; i++)
// {
// if (i == pre[i])
// {
// ans++;
// }
// }
// cout << ans << endl;
// return 0;
//}