Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- int con[1001][1001];
- vector<vector<int>> dp;
- int main(){
- //freopen("distbetweennodes.in", "r", stdin);
- cin >> n;
- dp.resize(n, vector<int>(n, 1e9));
- for(int i=0; i<n; i++){
- string s;
- cin >> s;
- for(int j=0; j<n; j++){
- if(s[j]-'0' == 1){
- dp[i][j] = s[j]-'0';
- }
- //cout << dp[i][j] << " ";
- }
- //cout << '\n';
- }
- //for(int i=0; i<n; i++){
- //for(int j=0; j<n; j++){
- //cout << dp[i][j] << '\n';
- //}
- //}
- //dp[0][0] = 0;
- for(int i=0; i<n; i++){
- dp[i][i] = 0;
- }
- for(int k=0; k<n; k++){
- for(int i=0; i<n; i++){
- for(int j=0; j<n; j++){
- dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
- }
- }
- }
- for(int i=0; i<n; i++){
- string s = "";
- for(int j=0; j<n; j++){
- cout << s << dp[i][j];
- s = " ";
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement