์๊ฐ ์ ํ | ๋ฉ๋ชจ๋ฆฌ ์ ํ | ์ ๋ต ๋น์จ |
1 ์ด | 256 MB | 51.358% |
11403๋ฒ: ๊ฒฝ๋ก ์ฐพ๊ธฐ
๊ฐ์ค์น ์๋ ๋ฐฉํฅ ๊ทธ๋ํ G๊ฐ ์ฃผ์ด์ก์ ๋, ๋ชจ๋ ์ ์ (i, j)์ ๋ํด์, i์์ j๋ก ๊ฐ๋ ๊ฒฝ๋ก๊ฐ ์๋์ง ์๋์ง ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
www.acmicpc.net
ํด๊ฒฐ๋ฐฉ์
๊ฐ ์ ์ ์ ๋ํด ์ฐ๊ฒฐ๋์ด ์๋ ์ ์ ์ผ๋ก DFS๋ก ํ์ํ๋ฉด์ ์ง๋๊ฐ๋ค๋ฉด arr[i][j] ๋ฅผ 1๋ก ๋ฐ๊พผ๋ค. ์ง๋๊ฐ์ง ์์๋ ์ ์ ์ ๋ํด์๋ง ํ์์ ๊ณ์ ์ด์ด๊ฐ๋ค. ๊ฐ ์ ์ ์ ๋ํด ์ฐ๊ฒฐ๋์ด ์๋ ์ ์ ์ ์ ๋ณด๋ฅผ ์๊ณ ์ถ์ผ๋ฏ๋ก n ๋ฒ ๋ฐ๋ณตํ๋ฉด ๋ชจ๋ ์ ์ ์ ์ ๋ณด๋ฅผ ์ ์ ์๋ค.
๋ฉ๋ชจ๋ฆฌ | ์๊ฐ |
2268 KB | 0 ms |
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
|
#include<iostream>
#include<string.h>
#include<vector>
using namespace std;
#define F(x,y,u,p) for(int x = 0; x<u; x++)for(int y = 0; y<p; y++)
int n, arr[105][105];
vector<vector<int>> v;
void dfs(int start, int present) {
for (auto& e : v[present]) {
if (arr[start][e]) continue;
arr[start][e] = 1;
dfs(start, e);
}
}
int main() {
scanf("%d", &n);
v.resize(n * n);
int a;
F(i, j, n, n) {
scanf("%d", &a);
if (a) v[i].push_back({ j });
}
for (int i = 0; i < n; i++) {
dfs(i, i);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
return 0;
}
|
cs |
'๐ฅ PS(Problem Solving) ๐ฅ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ] #10026 ์ ๋ก์์ฝ (0) | 2019.10.13 |
---|---|
[BOJ] #1260 DFS์ BFS (0) | 2019.10.13 |
[BOJ] #2589 ๋ณด๋ฌผ์ฌ (0) | 2019.10.13 |
[BOJ] #3187 ์์น๊ธฐ ๊ฟ (0) | 2019.10.13 |
[BOJ] #7562 ๋์ดํธ์ ์ด๋ (0) | 2019.10.13 |
๋๊ธ