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. input页面居中,软键盘覆盖input

    input框位于底部 对于ios的软键盘遮盖input输入框问题,网上已经有了一些解决办法,无非就是改变布局,再加scroll.js插件实现滚动, input框位于顶部 这种情况不会出现问题, inp ...

  2. 使用Xcode8的Instruments检测解决iOS内存泄露(leak)

    在苹果没有出ARC(自动内存管理机制)时,我们几乎有一半的开发时间都耗费在这么管理内存上.后来苹果很人性的出了ARC,虽然在很大程度上,帮助我们开发者节省了精力和时间.但是我们在开发过程中,由于种种原 ...

  3. Android Market 分析【安卓市场】

    安卓市场: 通过对表的分析,“下载任务”的数据来源于数据库[app_download],“已安装”的数据来源于数据库[software_installed]. 数据分析:----- bash-3.2# ...

  4. caffe源代码分析--math_functions.cu代码研究

    当中用到一个宏定义CUDA_KERNEL_LOOP 在common.hpp中有. #defineCUDA_KERNEL_LOOP(i,n) \ for(inti = blockIdx.x * bloc ...

  5. java 获取黑屏信息保存在list中,截取字符执行

    ArrayList<String> list1 = new ArrayList<String>(); Process p = Runtime.getRuntime().exec ...

  6. Protocol buffer序列化及其在微信蓝牙协议中的应用

    Protocol buffer是Google出品的一种轻便高效的结构化数据存储格式,可对结构化数据进行序列化,并具有语言无关.平台无关等特点,在通信协议和数据存储等领域已经得到广泛的应用.目前其已经提 ...

  7. TCP/IP协议原理与应用笔记08:对等层和对等实体

    1. 我们直接通过下面这个图,就可以直观了解: Outlook :收发邮件的软件组件. IE:浏览器. CutFTP:文件传输工具. 小结:因为为了完成不同的功能,所以会出现不同实体,这些不同的实体为 ...

  8. post 封装Map 发送请求

    package com.j1.weixin.util; import java.io.IOException; import java.util.Map; import java.util.Set; ...

  9. DataSet离线数据集实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  10. 关于C#中get和set

    在看书的时候看见了一段代码,有两个类person: public class person { public string name; } public class person { public s ...