poj 2983 Is the Information R...

poj 2983 Is the Information R...,第1张

poj 2983 Is the Information R...
#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;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4906194.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存