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?的更多相关文章

  1. POJ 2983-Is the Information Reliable

    Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...

  2. POJ 2983-Is the Information Reliable?(差分约束系统)

    题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...

  3. 图论--差分约束--POJ 2983--Is the Information Reliable?

    Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...

  4. 【POJ 2983】Is the Information Reliable?(差分约束系统)

    id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...

  5. POJ 之 Is the Information Reliable?

    B - Is the Information Reliable? Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I6 ...

  6. POJ2983 Is the Information Reliable?

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B                        B -  ...

  7. poj2983--Is the Information Reliable?(差分约束)

    Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 11125   A ...

  8. POJ 2983 Is the Information Reliable?(差分约束系统)

    http://poj.org/problem?id=2983 题意:N 个 defense stations,M条消息,消息有精确和模糊之分,若前边为P.则为精确消息,有两个defense stati ...

  9. ●POJ 2983 Is the Information Reliable?

    题链: http://poj.org/problem?id=2983 题解: 差分约束. 1).对于条件(P u v w),不难发现反映到图上就是: $dis[u]-dis[v]=w$,所以添加两条边 ...

随机推荐

  1. STUCTS LABLE ‘S BENEFIT

    {LJ?Dragon}[注]Struts标签的三个好处 RELATED LINKS 0.UTF-8 有无BOM的区别 UTF-8 BOM 06. 几款网页数据抓取软件 SOFTWARE_INTRODU ...

  2. Android WebView Error – Uncaught TypeError: Cannot call method ‘getItem’ of null at

    本质原因是js 没有判断dom 是否加载完毕 其实就是在dom 加载完毕之后处理事件 wv.getSettings().setDomStorageEnabled(true); 转自 蛙齋  http: ...

  3. CFBundleVersion与CFBundleShortVersionString,版本上架注意事项

    CFBundleVersion,标识(发布或未发布)的内部版本号.这是一个单调增加的字符串,包括一个或多个时期分隔的整数. CFBundleShortVersionString  标识应用程序的发布版 ...

  4. Java并发学习之二——获取和设置线程信息

    本文是学习网络上的文章时的总结,感谢大家无私的分享. Thread类的对象中保存了一些属性信息可以帮助我们辨别每个线程.知道它的一些信息 ID:每一个线程的独特标示: Name:线程的名称: Prio ...

  5. log4j配置文件详解---转

    使用步骤注意: 1. 从http://logging.apache.org/log4j/1.2/ 下载文件 2. 在src目录下加入log4j.properties,将jar包放入build -pat ...

  6. 《Android开发艺术探索》读书笔记 (1) 第1章 Activity的生命周期和启动模式

    第1章 Activity的生命周期和启动模式 1.1 Activity生命周期全面分析 1.1.1 典型情况下生命周期分析(1)一般情况下,当当前Activity从不可见重新变为可见状态时,onRes ...

  7. Python 代码实现模糊查询

    Python 代码实现模糊查询 1.导语: 模糊匹配可以算是现代编辑器(如 Eclipse 等各种 IDE)的一个必备特性了,它所做的就是根据用户输入的部分内容,猜测用户想要的文件名,并提供一个推荐列 ...

  8. css.day03

    css的分类(位置): css层叠样式表 1.内嵌 样式表 2.行内样式表 3. 外连 css选择器分类 基础选择器 标签 id选择器 类选择器 复合选择器 交集选择器(标签指定式)  span.on ...

  9. WinForm窗体之间传值

    当程序需要将一个窗体中的一些信息传给另一个窗体并让其使用时,就需要用到这个知识点 方法一:通过接受参数的窗体的构造函数传值 例:现有Form1和Form2两个窗体,二者都包含一个文本框,Form1还包 ...

  10. 关于User&nbsp;Defined&nbsp;Runtime&nbsp;Attributes的小技巧

    在用XIB里自定制view,button,label...的一些属性时,例如边框宽度,边框颜色等,如下图: