#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int N=1005,M=100000*4;int next[M],head[N],list[M],len[M],tot;void add(int a,int b,int c){tot++;list[tot]=b,len[tot]=c;next[tot]=head[a];head[a]=tot;}int n,m;int dist[N],tim[N];bool vis[N];bool spfa(){memset(dist,0x3f,sizeof dist);dist[0]=0;vis[0]=1;tim[0]++;queue<int>q;q.push(0);while(!q.empty()){int v=q.front();q.pop();vis[v]=0;for(int i=head[v];i;i=next[i]){int u=list[i];if(dist[u]>dist[v]+len[i]){dist[u]=dist[v]+len[i];if(!vis[u]){tim[u]++;if(tim[u]>n)return 0;vis[u]=1;q.push(u);}}}}return 1;}int main(){while(scanf("%d%d",&n,&m)!=EOF){memset(head,0,sizeof head);memset(vis,0,sizeof vis);memset(tim,0,sizeof tim);tot=0;for(int i=1;i<=m;i++){char c[10];scanf("%s",c);if(c[0]=='P'){int a,b,c;scanf("%d%d%d",&a,&b,&c);add(a,b,-c);add(b,a,c);}else{int a,b;scanf("%d%d",&a,&b);add(a,b,-1);}}for(int i=1;i<=n;i++)add(0,i,0);if(spfa())puts("Reliable");else puts("Unreliable");} return 0;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)