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. 《Web 前端面试指南》2、JavaScript 的 Bind 函数进阶

    使用 Bind() 设置方法中 this 对象 //<button>获取随机的人</button>​ //<input type="text"> ...

  2. 饿了么 ---Java面试

    下午去饿了么参加面试,其实也满怀期待,毕竟也是个大公司. 交通:偏外环,真北路 环境:感觉压抑,不通风,面试人很多,可能是屋子高度低,不舒服. 填了资料,等待面试,两轮,真是憋屈 都是搞技术的,何苦为 ...

  3. HTML5新特性之Canvas+drag(拖拽图像实现图像反转)

    1.什么是canvas 在网页上使用canvas元素时,会创建一块矩形区域,默认矩形区域宽度300px,高度150px.. 页面中加入canvas元素后,可以通过javascript自由控制.可以在其 ...

  4. java mysql驱动

    mysql驱动方式有三种, 1.第一种是先把jar包放在项目的目录下,通过添加jar包,是使用相对地址的,这样把项目复制到其它电脑也可以用 2.第二种方法是导入外部的jar包,是绝对地址,如果项目要复 ...

  5. PHPMailer中文说明

    PHPMailer中文说明 A开头: $AltBody --属性出自:PHPMailer ::$AltBody文件:class.phpmailer .php说明:该属性的设置是在邮件正文不支持HTML ...

  6. noip 2013 华容道

    /*双向bfs (得分和单项的一样多....)70*/ #include<iostream> #include<cstdio> #include<cstring> ...

  7. 【开源java游戏框架libgdx专题】-09-动画的使用

    1.Animation类介绍   Api定义:动画是由多个帧,在设定的时间间隔序列显示.比如,一个跑步的人一个动画可以通过运行时播放这些图像无限拍照他了. 功能用法:管理动画,设置随即播放模式和播放顺 ...

  8. OD: RPC - MS06040 & MS08067

    RPC 漏洞简介 Remote Procedure Call,分布式计算中常用到的技术.两台计算机通信过程可以分为两种形式:一种是数据的交换,另一种是进程间通信.RPC 属于进程间通信. RPC 就是 ...

  9. call, apply, bind作用

    call, apply作用就是(改变方法中的this指向)借用别人的方法来调用,就像调用自己的一样 function Person(name) { this.name = name; } Person ...

  10. querystring,parse和stringify相互转换

    var querystring = require('querystring');var str = 'name==zfpx@age==8';//手工指定字段分隔符和 keyvalue分隔符var q ...