差分约束找条件。
1,p a b x
b-a>=x;
a-b<=-x;
2,v a b
b-a>=1;
判断条件
b>a-dis;
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct list
{int l;int r;int dis;
}node[200001];
int w[200001];
int dist[1001];
int num=1;
void add(int a,int b,int c)
{node[num].l=a;node[num].r=b;node[num++].dis=c;
}
int main()
{int n,m,i,j,a,b,c;char str;while(~scanf("%d %d",&m,&n)){getchar();num=1;memset(dist,0,sizeof(dist));for(i=0;i<n;i++){scanf("%c",&str);if(str=='P'){getchar();scanf("%d %d %d%*c",&a,&b,&c);add(a,b,c);add(b,a,-c);}else{getchar();scanf("%d %d%*c",&a,&b);add(a,b,1);}}int leap;for(i=0;i<m;i++){leap=-1;for(j=1;j<num;j++){if(dist[node[j].r]>dist[node[j].l]-node[j].dis){dist[node[j].r]=dist[node[j].l]-node[j].dis;leap=1;}}if(leap==-1)break;}if(leap==-1)printf("Reliable\n");else printf("Unreliable\n");}return 0;
}