forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11403.cpp
49 lines (40 loc) · 867 Bytes
/
11403.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
// Authored by : scsc3204
// Co-authored by : -
// http://boj.kr/9205a3a58c764ea49b7d40ccc012481c
#include <bits/stdc++.h>
using namespace std;
int n;
bool am[102][102];
bool vis[102];
bool dfs(int st, int tar) {
fill(vis, vis + n + 2, 0);
stack<int> stk;
stk.push(st);
while(!stk.empty()) {
int cur = stk.top();
stk.pop();
if(vis[cur]) continue;
if(cur != st) vis[cur] = 1;
for(int nxt = 0; nxt < n; nxt++) {
if(vis[nxt]) continue;
if(am[cur][nxt]) {
if(nxt == tar) return true;
stk.push(nxt);
}
}
}
return false;
}
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> am[i][j];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
cout << dfs(i, j) << ' ';
cout << '\n';
}
}