poj 2983 差分约束
来源:互联网 发布:php 整数保留2位小数 编辑:程序博客网 时间:2024/05/16 16:17
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<map>
#define PI acos(-1.0)
typedef long long LL;
const int MAX=0xfffffff;
using namespace std;
const int mx=200020;
int n,m;
int cnt;
class node {
public:
int u,v,w;
}edge[mx];
int dist[1010];
void bellman_ford( )
{
for(int i=0;i<=n;i++) dist[i]=MAX;
bool ok;
for(int i=1;i<n;i++)
{
ok=0;
for(int j=0;j<cnt;j++)
if(dist[edge[j].v]>dist[edge[j].u]-edge[j].w)
{
dist[edge[j].v]=dist[edge[j].u]-edge[j].w;
ok=1;
}
//for(int j=0;j<cnt;j++) //不知道为什么自己加上这个条件就WA
// if(dist[edge[j].v]>dist[edge[j].u]-1)
// {
// dist[edge[j].v]=dist[edge[j].u]-1;
// ok=1;
// }
if(!ok) break;
}
if(ok) printf("Unreliable\n");
else printf("Reliable\n");
}
int main( )
{
freopen("1.txt","r",stdin);
while(scanf("%d %d",&n,&m)!=EOF)
{
cnt=0;
while(m--)
{
char s[2];
scanf("%s",s);
int a,b,x;
if(s[0]=='P')
{
scanf("%d %d %d",&a,&b,&x);
edge[cnt].u=a,edge[cnt].v=b,edge[cnt++].w=x;
edge[cnt].u=b,edge[cnt].v=a,edge[cnt++].w=-x;
}
else if(s[0]=='V')
{
scanf("%d %d",&a,&b);
edge[cnt].u=a,edge[cnt].v=b,edge[cnt++].w=1;
}
}
bellman_ford( );
}
return 0;
}
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<map>
#define PI acos(-1.0)
typedef long long LL;
const int MAX=0xfffffff;
using namespace std;
const int mx=200020;
int n,m;
int cnt;
class node {
public:
int u,v,w;
}edge[mx];
int dist[1010];
void bellman_ford( )
{
for(int i=0;i<=n;i++) dist[i]=MAX;
bool ok;
for(int i=1;i<n;i++)
{
ok=0;
for(int j=0;j<cnt;j++)
if(dist[edge[j].v]>dist[edge[j].u]-edge[j].w)
{
dist[edge[j].v]=dist[edge[j].u]-edge[j].w;
ok=1;
}
//for(int j=0;j<cnt;j++) //不知道为什么自己加上这个条件就WA
// if(dist[edge[j].v]>dist[edge[j].u]-1)
// {
// dist[edge[j].v]=dist[edge[j].u]-1;
// ok=1;
// }
if(!ok) break;
}
if(ok) printf("Unreliable\n");
else printf("Reliable\n");
}
int main( )
{
freopen("1.txt","r",stdin);
while(scanf("%d %d",&n,&m)!=EOF)
{
cnt=0;
while(m--)
{
char s[2];
scanf("%s",s);
int a,b,x;
if(s[0]=='P')
{
scanf("%d %d %d",&a,&b,&x);
edge[cnt].u=a,edge[cnt].v=b,edge[cnt++].w=x;
edge[cnt].u=b,edge[cnt].v=a,edge[cnt++].w=-x;
}
else if(s[0]=='V')
{
scanf("%d %d",&a,&b);
edge[cnt].u=a,edge[cnt].v=b,edge[cnt++].w=1;
}
}
bellman_ford( );
}
return 0;
}
0 0
- poj 2983 差分约束
- Poj 2983 (差分约束系统)
- POJ 2983 SPFA 差分约束
- poj 2983(差分约束)
- poj 2983 差分约束+SPFA
- poj 2983 (差分约束系统)
- POJ 2983 (差分约束)
- poj 2983 spfa差分约束
- POJ 2983 差分约束系统
- poj 2983 差分约束系统 题解
- POJ 1364 差分约束
- POJ 1716 差分约束
- POJ 1275 差分约束
- poj 3169 差分约束
- poj 1201 差分约束
- POJ 3169 差分约束
- poj 1201 差分约束
- poj 1275 差分约束
- DedeCMS 友情链接按分类网站类型调用的方法
- TAR命令的基本使用方法详解
- unity3d math 常用的数学
- hdu4973(线段树)
- SpringMVC一次请求多次进入Control的原因
- poj 2983 差分约束
- Techniques for preventing overfitting in training Deep Neural Networks
- 用curl模拟http请求获取网页
- 文件操作一些总结
- IP(Internet Protocal) 地址 说明
- c++Primer学习笔记之一:程序的编译与执行
- STOMP协议说明书-1.2版
- HDU 4091Zombie’s Treasure Chest (数学加暴力)
- android手机连接PC无法正常安装驱动