Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

TLE爆吐,说好的Floyed可以过的呢

Posted by 123rrc at 2022-08-27 15:32:17 on Problem 3259
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator