-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10159.cpp
More file actions
47 lines (47 loc) · 1.11 KB
/
Copy path10159.cpp
File metadata and controls
47 lines (47 loc) · 1.11 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
#include <iostream>
#include <vector>
#include <stack>
#include <string.h>
using namespace std;
const int MAX = 101;
vector<int> dv[MAX], uv[MAX];
bool check[MAX];
int dfs(vector<int> v[], int start){
stack<int> s;
s.push(start);
check[start] = true;
int count = 0;
while(!s.empty()){
int current_node = s.top();
s.pop();
for(int i = 0 ; i<v[current_node].size();i++){
int next_node = v[current_node][i];
if(!check[next_node]){
check[next_node] = true;
s.push(current_node);
s.push(next_node);
count++;
}
}
}
return count;
}
int main(){
int n,m, a,b;
cin >> n >> m;
for(int i = 0 ; i < m;i++){
cin >> a >> b;
dv[a].push_back(b);
uv[b].push_back(a);
}
for(int i =1;i <=n;i++){
if(i!= 1){
cout << "\n";
}
int dn = dfs(dv,i), un = dfs(uv,i);
// cout << i << "번째: dn: " <<dn << " un: " << un;
cout << n- 1 -dn - un;
memset(check,false,sizeof(check));
}
return 0;
}