cepiloth 2018. 9. 2. 15:31
반응형

 

https://www.acmicpc.net/problem/11403

 

 

키워드 - 플로이드 와샬 알고리즘, 그래프 였나 tekken 님이 알려줌

 

Source

#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <math.h>
#include <memory.h>
using namespace std;
 
#define MAX_SIZE 100
#define INF 0x7fffffff
#define CENDL "\n"
#define ll long long
 
#define c_reverse(s) reverse(s.begin(), s.end())
#define c_sort(s) sort(s.begin(), s.end())
#define print_vector(v) for(int i=0; i<v.size(); i++) cout << v[i];
 
int table[101][101] = { 0, };
int main() {
 
    cin.tie(0);
    std::ios::sync_with_stdio(false);
 
    int n; cin >> n;
 
    for (int i = 0; i < n; i++) {
        for (int j=0; j < n; j++) {
            cin >> table[i][j];
        }
    }
 
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (table[i][k] && table[k][j]) {
                    //cout << 1 << " ";
                    table[i][j] = 1;
                }
            }
        }
    }
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << table[i][j] << " ";
        }
        cout << CENDL;
    }
 
    return 0;
}

 

반응형