poj 2983Is the Information Reliable?
http://poj.org/problem?id=2983
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxm 5000100
#define maxn 3010
using namespace std;
int head[maxn],next[maxn],dis[maxn];
bool vis[maxn];
int e,n,m;
const int inf=<<;
struct node
{
int u,v,c;
node(){}
node(int u,int v,int c):u(u),v(v),c(c){}
}p[maxm]; void addnode(int u,int v,int c)
{
p[e]=node(u,v,c);
next[e]=head[u];head[u]=e++;
} void inti()
{
memset(head,-,sizeof(head));
memset(next,-,sizeof(next));
e=;
for(int i=; i<m; i++)
{
char ch;int u,v,c;
scanf("%c",&ch);
if(ch=='P')
{
scanf("%d%d%d",&u,&v,&c);
getchar();
addnode(u,v,-c);
addnode(v,u,c);
}
else if(ch=='V')
{
scanf("%d%d",&u,&v);
getchar();
addnode(u,v,-);
}
}
} void Bellman_ford()
{
bool flag;
for(int i=; i<=n; i++) dis[i]=inf;
for(int i=; i<=n; i++)
{
flag=true;
for(int j=; j<e; j++)
{
if(dis[p[j].v]>dis[p[j].u]+p[j].c)
{
dis[p[j].v]=dis[p[j].u]+p[j].c;
flag=false;
}
}
if(flag) break;
}
if(!flag) printf("Unreliable\n");
else printf("Reliable\n");
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
inti();
Bellman_ford();
}
return ;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxm 500010
#define maxn 3010
using namespace std;
int head[maxn],next[maxn],dis[maxn];
bool vis[maxn];
int e,n,m;
const int inf=<<;
struct node
{
int u,v,c;
node(){}
node(int u,int v,int c):u(u),v(v),c(c){}
}p[maxm]; void addnode(int u,int v,int c)
{
p[e]=node(u,v,c);
next[e]=head[u];head[u]=e++;
} void inti()
{
memset(head,-,sizeof(head));
memset(next,-,sizeof(next));
e=;
for(int i=; i<m; i++)
{
char ch;
int u,v,c;
scanf("%c",&ch);
if(ch=='P')
{
scanf("%d%d%d",&u,&v,&c);
getchar();
addnode(u,v,-c);
addnode(v,u,c);
}
else if(ch=='V')
{
scanf("%d%d",&u,&v);
getchar();
addnode(u,v,-);
}
}
} void Bellman_ford()
{
bool flag;
for(int i=; i<=n; i++) dis[i]=inf;
for(int i=; i<=n; i++)
{
for(int j=; j<e; j++)
{
if(dis[p[j].v]>dis[p[j].u]+p[j].c)
{
dis[p[j].v]=dis[p[j].u]+p[j].c;
}
}
}
flag=true;
for(int j=; j<e; j++)
{
if(dis[p[j].v]>dis[p[j].u]+p[j].c)
{
flag=false;
break;
}
}
if(!flag) printf("Unreliable\n");
else printf("Reliable\n");
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
inti();
Bellman_ford();
}
return ;
}
poj 2983Is the Information Reliable?的更多相关文章
- POJ 2983-Is the Information Reliable
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...
- POJ 2983-Is the Information Reliable?(差分约束系统)
题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...
- 图论--差分约束--POJ 2983--Is the Information Reliable?
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...
- 【POJ 2983】Is the Information Reliable?(差分约束系统)
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...
- POJ 之 Is the Information Reliable?
B - Is the Information Reliable? Time Limit:3000MS Memory Limit:131072KB 64bit IO Format:%I6 ...
- POJ2983 Is the Information Reliable?
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B B - ...
- poj2983--Is the Information Reliable?(差分约束)
Is the Information Reliable? Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 11125 A ...
- POJ 2983 Is the Information Reliable?(差分约束系统)
http://poj.org/problem?id=2983 题意:N 个 defense stations,M条消息,消息有精确和模糊之分,若前边为P.则为精确消息,有两个defense stati ...
- ●POJ 2983 Is the Information Reliable?
题链: http://poj.org/problem?id=2983 题解: 差分约束. 1).对于条件(P u v w),不难发现反映到图上就是: $dis[u]-dis[v]=w$,所以添加两条边 ...
随机推荐
- dos 命令
DOS远程桌面连接命令 mstsc /v: 192.168.1.250 /console cmd 运行 command删除文件 rd 文件名/S创建文件 MD 文件名 1. net user admi ...
- Hard 随机洗牌函数 @CareerCup
第i个元素和index在[i,length-1]之间的一个数随机交换 package Hard; import CtCILibrary.AssortedMethods; /** * * Write a ...
- Java读书笔记二(封装类)
1.介绍 都知道java中基本数据类型有非常多,比方string,int--,可是基本数据类型与对象之间是不同的.但非常多情况下,我们希望将基本数据类型当作对象使用,这时候就须要用到封装类. 2.封装 ...
- pat 1060. Are They Equal (25)
题目意思直接,要求将两个数转为科学计数法表示,然后比较是否相同 不过有精度要求 /* test 6 3 0.00 00.00 test 3 3 0.1 0.001 0.001=0.1*10^-2 p ...
- MaxReceivedMessageSize :已超过传入消息(65536)的最大消息大小配额
做的windows应用程序(后台调用webservice),数据量大的时候,报错如下: System.ServiceModel.CommunicationException: 已超过传入消息(6553 ...
- 3 Ways to Preload Images with CSS, JavaScript, or Ajax---reference
Preloading images is a great way to improve the user experience. When images are preloaded in the br ...
- warning : json_decode(): option JSON_BIGINT_AS_STRING not implemented in xxx
先来一段json_decode官方说明 mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, i ...
- H.264视频在android手机端的解码与播放(转)
随着无线网络和智能手机的发展,智能手机与人们日常生活联系越来越紧密,娱乐.商务应用.金融应用.交通出行各种功能的软件大批涌现,使得人们的生活丰富多彩.快捷便利,也让它成为人们生活中不可取代的一部分.其 ...
- struts2学生信息管理系统篇章④
把util包中的代码做了一下注释,分享一下 DateUtil 类 package com.java1234.util; import java.text.SimpleDateFormat; impor ...
- window.applicationCache事件,介绍
1.关于applicationCache对象 在IE和Google中 为ApplicationCache对象 而在FF中为 OfflineResourceList对象 通过ApplicationCac ...