https://programmers.co.kr/learn/courses/30/lessons/49191
#include <string>
#include <vector>
#include <iostream>
using namespace std;
bool check[101] = {false, };
int dfs(int in, vector<vector<int>> p){
int nodes = 0;
for(int i=0;i<p[in].size();i++){
if(check[p[in][i]] == false){
check[p[in][i]] = true;
nodes += dfs(p[in][i], p);
}
}
return nodes+1;
}
int solution(int n, vector<vector<int>> results) {
int answer = 0;
vector<vector<int>> c(n);
vector<vector<int>> p(n);
for(int i=0;i<results.size();i++){
c[results[i][0]-1].push_back(results[i][1]-1);
p[results[i][1]-1].push_back(results[i][0]-1);
}
for(int i=0;i<n;i++){
int pn = dfs(i, p)-1;
int cn = dfs(i, c)-1;
for(int j=0;j<101;j++)
check[j] = false;
if(pn + cn == n-1)
answer++;
}
return answer;
}
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#include <iostream>
using namespace std;
int solution(int n, vector<vector<int>> results) {
int answer = 0;
bool arr[101][101];
memset(arr, 0, sizeof(arr));
for(int i = 0; i < results.size(); i++){
int a = results[i][0];
int b = results[i][1];
arr[a][b] = true;
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(arr[i][k] && arr[k][j]) arr[i][j] = true;
}
}
}
for(int i = 1; i <= n; i++){
int cnt = 0;
for(int j = 1; j <= n; j++)
cnt += (arr[i][j] + arr[j][i]);
if(cnt == n-1) answer++;
}
return answer;
}