백준 알고리즘 11403번 : 경로 찾기

Zoo Da·2021년 12월 1일
0

백준 알고리즘

목록 보기
274/337
post-thumbnail

링크

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

sol1)

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;

int dist[101][101];
const int INF = 1e9 + 7;

int32_t main() {
  fastio;
  int n; cin >> n;
  for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
    int t; cin >> t;
    if(t) dist[i][j] = t;
    else dist[i][j] = INF;
  }
  // floyd
  for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      cout << (dist[i][j]==INF ? 0 : 1) << ' ';
    }
    cout << "\n";
  }
}
profile
메모장 겸 블로그

0개의 댓글