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

注意图可能不联通,把所有的点都入一次队即可

Posted by 1710252115 at 2019-02-17 16:44:06 on Problem 2983
/*固定距离的双向路,建立两个边,即:f[a]-f[b]>=val和f[a]-f[b]<=val,对于不确定的,建立一个边,即:f[a]-f[b]>=1。
注意图可能不联通,所以spfa的时候所有元素都要入栈一次。
如果想设置 源 的话,出门左转(雾)
400+MS水过。
*/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
  
#include<stdio.h>
#include<string.h> 
#include<math.h> 
   
//#include<map>  
#include<set>
#include<deque> 
#include<queue> 
#include<stack> 
#include<bitset>
#include<string> 
#include<fstream>
#include<iostream> 
#include<algorithm> 
using namespace std; 
  
#define ll long long 
#define Pair pair<int,int>
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// 水印
//std::ios::sync_with_stdio(false);
//  register
const int MAXN=1e3+10;
const int INF32=0x3f3f3f3f;
const ll INF64=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
const double PI=acos(-1.0);

struct node{
	int v,nxt,val;
	node(int _v=0,int _val=0,int _nxt=0){
		v=_v;val=_val;nxt=_nxt;
	}
}edge[MAXN*MAXN];
int head[MAXN],ecnt;
int stk[MAXN*MAXN],tot;
int dis[MAXN],vis[MAXN],sum[MAXN];
int n,m,flag;

void intt(){
	clean(head,-1);
	ecnt=0;tot=0;
}
void add(int u,int v,int val){
	edge[ecnt]=node(v,val,head[u]);
	head[u]=ecnt++;
}
void dfs_spfa(int str){
	for(int i=1;i<=n;++i){
		dis[i]=0;vis[i]=1;sum[i]=1;
		stk[tot++]=i;
	}
//	clean(dis,INF32);dis[str]=0;
//	clean(vis,0);vis[str]=1;
//	clean(sum,0);sum[str]++;
//	stk[tot++]=str;
	while(tot){
		int u=stk[--tot];vis[u]=0;
		//printf("\nu: %d\n",u);
		for(int i=head[u];i+1;i=edge[i].nxt){
			int v=edge[i].v;
			if(dis[v]>dis[u]+edge[i].val){
				dis[v]=dis[u]+edge[i].val;
				//printf("v: %d %d--",v,dis[v]);
				if(vis[v]==0){
					vis[v]=1;
					stk[tot++]=v;
					sum[v]++;
					if(sum[v]>n){
						flag=1;return ;
					}
				}
			}
		}
	}
}
int main(){
    while(~scanf("%d%d",&n,&m)){
    	intt();char oper[5];int a,b,val;
    	for(int i=1;i<=m;++i){
    		scanf("%s",&oper);
    		if(oper[0]=='P'){
    			scanf("%d%d%d",&a,&b,&val);
    			add(b,a,val);
    			add(a,b,-val);
			}
			else{
				scanf("%d%d",&a,&b);
				add(a,b,-1);
			}
		}
//		for(int i=1;i<=n;++i){
//			add(0,i,0);
//		}
		flag=0;
		dfs_spfa(0);
		if(flag)	printf("Unreliable\n");
		else	printf("Reliable\n");
	}
}

/*

*/

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