Submission #1692235


Source Code Expand

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int dp1[5010][5010]={0};
int dp2[5010][5010]={0};
int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		vvi cost(n,vi(n));
		rep(i,n)rep(j,n)cin>>cost[i][j];
		rep(i,n)rep(j,n)if(cost[i][j]==-1)cost[i][j]=inf;
		vvi t=cost;
		rep(k,n)rep(i,n)rep(j,n)
			t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
//		rep(i,n){rep(j,n)cout<<" "<<t[i][j];cout<<endl;}
//		cout<<endl;
		bool h=true;
		rep(i,n)rep(j,n)if(i==j&&(t[i][j]||cost[i][j])||cost[i][j]-t[i][j])h=false;
		if(h)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}









Submission Info

Submission Time
Task C - 最短経路
User ixmel_rd
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1941 Byte
Status AC
Exec Time 9 ms
Memory 256 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 1 ms 256 KB
10_random_00.txt AC 8 ms 256 KB
10_random_01.txt AC 8 ms 256 KB
10_random_02.txt AC 8 ms 256 KB
10_random_03.txt AC 8 ms 256 KB
10_random_04.txt AC 8 ms 256 KB
10_random_05.txt AC 8 ms 256 KB
10_random_06.txt AC 8 ms 256 KB
10_random_07.txt AC 8 ms 256 KB
10_random_08.txt AC 8 ms 256 KB
10_random_09.txt AC 8 ms 256 KB
10_random_10.txt AC 8 ms 256 KB
10_random_11.txt AC 8 ms 256 KB
10_random_12.txt AC 8 ms 256 KB
10_random_13.txt AC 8 ms 256 KB
10_random_14.txt AC 8 ms 256 KB
10_random_15.txt AC 8 ms 256 KB
10_random_16.txt AC 8 ms 256 KB
10_random_17.txt AC 8 ms 256 KB
10_random_18.txt AC 8 ms 256 KB
10_random_19.txt AC 8 ms 256 KB
10_random_20.txt AC 8 ms 256 KB
10_random_21.txt AC 8 ms 256 KB
10_random_22.txt AC 8 ms 256 KB
10_random_23.txt AC 8 ms 256 KB
10_random_24.txt AC 8 ms 256 KB
10_random_25.txt AC 8 ms 256 KB
10_random_26.txt AC 8 ms 256 KB
10_random_27.txt AC 8 ms 256 KB
10_random_28.txt AC 8 ms 256 KB
10_random_29.txt AC 8 ms 256 KB
22_random_30.txt AC 8 ms 256 KB
22_random_31.txt AC 8 ms 256 KB
23_coplete_32.txt AC 9 ms 256 KB
23_coplete_33.txt AC 9 ms 256 KB
24_path_34.txt AC 8 ms 256 KB
24_path_35.txt AC 8 ms 256 KB
25_tree_36.txt AC 8 ms 256 KB
25_tree_37.txt AC 8 ms 256 KB
26_noedge_38.txt AC 8 ms 256 KB
27_dot_39.txt AC 1 ms 256 KB