Submission #684612


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001;
int N;
int A[30][30];
int B[30][30];
void solve(){
    cin>>N;
    rep(i,N)rep(j,N)cin>>A[i][j];

    rep(i,N){
        if(A[i][i]!=0){
            cout<<"NO"<<endl;
            return;
        }
    }

    rep(i,N)rep(j,N){
        if(A[i][j]==-1)B[i][j]=INF;
        else B[i][j]=A[i][j];
    }
    rep(k,N)rep(i,N)rep(j,N)chmin(B[i][j],B[i][k]+B[k][j]);
    rep(i,N)rep(j,N){
        if((A[i][j]==-1&&B[i][j]!=INF)||(A[i][j]>=0&&A[i][j]!=B[i][j])){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}

signed main(){
    int T;cin>>T;
    while(T--)solve();
    return 0;
}

Submission Info

Submission Time
Task C - 最短経路
User latte0119
Language C++11 (GCC 4.9.2)
Score 100
Code Size 1253 Byte
Status AC
Exec Time 39 ms
Memory 932 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 41
Set Name Test Cases
All 00_sample.txt, 10_random_00.txt, 10_random_01.txt, 10_random_02.txt, 10_random_03.txt, 10_random_04.txt, 10_random_05.txt, 10_random_06.txt, 10_random_07.txt, 10_random_08.txt, 10_random_09.txt, 10_random_10.txt, 10_random_11.txt, 10_random_12.txt, 10_random_13.txt, 10_random_14.txt, 10_random_15.txt, 10_random_16.txt, 10_random_17.txt, 10_random_18.txt, 10_random_19.txt, 10_random_20.txt, 10_random_21.txt, 10_random_22.txt, 10_random_23.txt, 10_random_24.txt, 10_random_25.txt, 10_random_26.txt, 10_random_27.txt, 10_random_28.txt, 10_random_29.txt, 22_random_30.txt, 22_random_31.txt, 23_coplete_32.txt, 23_coplete_33.txt, 24_path_34.txt, 24_path_35.txt, 25_tree_36.txt, 25_tree_37.txt, 26_noedge_38.txt, 27_dot_39.txt
Case Name Status Exec Time Memory
00_sample.txt AC 24 ms 804 KB
10_random_00.txt AC 37 ms 928 KB
10_random_01.txt AC 38 ms 924 KB
10_random_02.txt AC 35 ms 796 KB
10_random_03.txt AC 36 ms 728 KB
10_random_04.txt AC 36 ms 800 KB
10_random_05.txt AC 37 ms 928 KB
10_random_06.txt AC 35 ms 928 KB
10_random_07.txt AC 36 ms 916 KB
10_random_08.txt AC 36 ms 920 KB
10_random_09.txt AC 37 ms 932 KB
10_random_10.txt AC 37 ms 924 KB
10_random_11.txt AC 38 ms 792 KB
10_random_12.txt AC 38 ms 796 KB
10_random_13.txt AC 37 ms 728 KB
10_random_14.txt AC 36 ms 728 KB
10_random_15.txt AC 37 ms 728 KB
10_random_16.txt AC 35 ms 796 KB
10_random_17.txt AC 35 ms 932 KB
10_random_18.txt AC 35 ms 800 KB
10_random_19.txt AC 35 ms 920 KB
10_random_20.txt AC 37 ms 912 KB
10_random_21.txt AC 37 ms 800 KB
10_random_22.txt AC 36 ms 796 KB
10_random_23.txt AC 39 ms 920 KB
10_random_24.txt AC 38 ms 924 KB
10_random_25.txt AC 38 ms 796 KB
10_random_26.txt AC 38 ms 920 KB
10_random_27.txt AC 37 ms 800 KB
10_random_28.txt AC 38 ms 804 KB
10_random_29.txt AC 37 ms 920 KB
22_random_30.txt AC 36 ms 792 KB
22_random_31.txt AC 36 ms 800 KB
23_coplete_32.txt AC 39 ms 800 KB
23_coplete_33.txt AC 39 ms 916 KB
24_path_34.txt AC 38 ms 800 KB
24_path_35.txt AC 38 ms 924 KB
25_tree_36.txt AC 38 ms 920 KB
25_tree_37.txt AC 39 ms 916 KB
26_noedge_38.txt AC 37 ms 916 KB
27_dot_39.txt AC 23 ms 920 KB