| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
TLE爆吐,说好的Floyed可以过的呢#include<iostream>
#include<memory.h>
#define inf 0x3f3f3f3f
using namespace std;
int mapp[1001][1001]={},n,m,l,u,v,w;
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(mapp,0x3f,sizeof(mapp));
scanf("%d%d%d",&n,&m,&l);
for(int i=1;i<=n;i++){
mapp[i][i]=0;
}
while(m--){
scanf("%d%d%d",&u,&v,&w);
if(w<mapp[u][v]){
mapp[u][v]=w;
mapp[v][u]=w;
}
}
while(l--){
scanf("%d%d%d",&u,&v,&w);
if(-w<mapp[u][v]){
mapp[u][v]=-w;
}
}
int flag=0;
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(mapp[i][k]+mapp[k][j]<mapp[i][j]){
mapp[i][j]=mapp[i][k]+mapp[k][j];
}
}
if(mapp[i][i]<0){
flag=1;
}
}
}
if(flag){
printf("YES\n");
}else{
printf("NO\n");
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator