๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 11403๋ฒˆ - ๊ฒฝ๋กœ ์ฐพ๊ธฐ

by dkswnkk 2021. 10. 27.
 

11403๋ฒˆ: ๊ฒฝ๋กœ ์ฐพ๊ธฐ

๊ฐ€์ค‘์น˜ ์—†๋Š” ๋ฐฉํ–ฅ ๊ทธ๋ž˜ํ”„ G๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋ชจ๋“  ์ •์  (i, j)์— ๋Œ€ํ•ด์„œ, i์—์„œ j๋กœ ๊ฐ€๋Š” ๊ฒฝ๋กœ๊ฐ€ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int N;
int graph[101][101];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;

    for (int i = 1; i <= N; i++) {
        for (int k = 1; k <= N; k++) {
            int value; cin >> value;
            graph[i][k] = value;
        }
    }
        for (int k = 1; k <= N; k++) {
            for (int a = 1; a <= N; a++) {
                for (int b = 1; b <= N; b++) {
                    if (graph[a][k] && graph[k][b]) graph[a][b] = 1;
                }
            }
        }

    for (int a = 1; a <= N; a++) {
        for (int b = 1; b <= N; b++) {
            cout << graph[a][b]<<' ';
        }
        cout << "\n";
    }
}

๋Œ“๊ธ€