hdoj 3952 World Exhibition
World Exhibition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1383 Accepted Submission(s):
679
the World Exhibition. So there are always a lot of people who are standing along
a straight line waiting for entering. Assume that there are N (2 <= N <=
1,000) people numbered 1..N who are standing in the same order as they are
numbered. It is possible that two or more person line up at exactly the same
location in the condition that those visit it in a group.
There is
something interesting. Some like each other and want to be within a certain
distance of each other in line. Some really dislike each other and want to be
separated by at least a certain distance. A list of X (1 <= X <= 10,000)
constraints describes which person like each other and the maximum distance by
which they may be separated; a subsequent list of Y constraints (1 <= Y <=
10,000) tells which person dislike each other and the minimum distance by which
they must be separated.
Your job is to compute, if possible, the maximum
possible distance between person 1 and person N that satisfies the distance
constraints.
test.
The next line: Three space-separated integers: N, X, and Y.
The next X lines: Each line contains three space-separated positive
integers: A, B, and C, with 1 <= A < B <= N. Person A and B must be at
most C (1 <= C <= 1,000,000) apart.
The next Y lines: Each line
contains three space-separated positive integers: A, B, and C, with 1 <= A
< B <= C. Person A and B must be at least C (1 <= C <= 1,000,000)
apart.
possible, output -1. If person 1 and N can be arbitrarily far apart, output -2.
Otherwise output the greatest possible distance between person 1 and N.
#include<stdio.h>
#include<string.h>
#include<queue>
#define MAX 100000
#define INF 0x3f3f3f
using namespace std;
int head[MAX];
int n,m,s,ans;
int dis[MAX],vis[MAX];
int used[MAX];
struct node
{
int u,v,w;
int next;
}edge[MAX];
void add(int u,int v,int w)
{
edge[ans].u=u;
edge[ans].v=v;
edge[ans].w=w;
edge[ans].next=head[u];
head[u]=ans++;
}
void init()
{
ans=0;
memset(head,-1,sizeof(head));
}
void getmap()
{
int i,j;
while(m--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
while(s--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(b,a,-c);
}
}
void spfa(int sx)
{
int i,j;
queue<int>q;
memset(vis,0,sizeof(vis));
memset(used,0,sizeof(used));
for(i=1;i<=n;i++)
dis[i]=i==sx?0:INF;
vis[sx]=1;
used[sx]++;
q.push(sx);
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=0;
for(i=head[u];i!=-1;i=edge[i].next)
{
int top=edge[i].v;
if(dis[top]>dis[u]+edge[i].w)
{
dis[top]=dis[u]+edge[i].w;
if(!vis[top])
{
vis[top]=1;
q.push(top);
used[top]++;
if(used[top]>n)
{
printf("-1\n");
return ;
}
}
}
}
}
if(dis[n]==INF)
printf("-2\n");
else
printf("%d\n",dis[n]);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&s);
init();
getmap();
spfa(1);
}
return 0;
}
hdoj 3952 World Exhibition的更多相关文章
- 【HDOJ】3592 World Exhibition
基础差分约束. /* 3592 */ #include <iostream> #include <algorithm> #include <queue> #incl ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
- POJ2184 Cow Exhibition[DP 状态负值]
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12420 Accepted: 4964 D ...
随机推荐
- OpenCV2学习笔记01:Linux下OpenCV开发环境的搭建
个人已经厌倦了Windows下的开发方式,于是决定转到Linux平台上来,当然我也知道这个转变会很艰辛,但是我还是要坚持.所以,后面的所有开发我都会基于Linux和Qt,先从开发环境的搭建开始做起,当 ...
- centos nginx
1.关闭SELinux 查看SELinux状态: (1)/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: ...
- c#自动更新+安装程序的制作 (转)
c#自动更新+安装程序的制作 (转) http://blog.csdn.net/myhuli120/article/details/6927588 一.自动更新的实现 让客户端实现自动更新,通常做法 ...
- #include<filename.h> 与 #include“filename.h”
#include<filename.h>:从标准库路径去寻找该文件,对于VC来说,应该还包括VC环境设置选项中的包含目录以及工程属性中指定的目录. #include“filename.h” ...
- CTSC && APIO 总结
先说CTSC吧,第一试其实不难但是下意识觉得CTSC不就只能骗分吗,然后就全上暴力了.然而第二题再一次看漏了条件,即答案总和小于等于1e6.第三题现在回想起来要不然就是没有思考,要不然就是没学过数学, ...
- bzoj 3781: 小B的询问 分块
3781: 小B的询问 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 196 Solved: 135[Submit][Status] Descrip ...
- JavaSE 国际化 简单例子
①在src下添加两个文件: base_zh_CN.properties Test=\u8fd9\u662f\u4e2d\u6587 base_en_US.properties Test=english ...
- C#学习笔记一:C#开发环境的设置
C#是.NET Framework的一部分,用于编写.NET应用程序. C#集成开发环境(IDE) 微软提供了以下C#编程开发工具: Visual Studio 2010 (VS) Visual C# ...
- usb.ids
# # List of USB ID's # # Maintained by Vojtech Pavlik <vojtech@suse.cz> # If you have any new ...
- FishEye简介
前言 在项目开发过程中,随着开发的进行,将有大量的代码编写提交到代码仓库,如何能全面准确的了解源代码的变化,提交的频率,代码量的趋势,发现代码的缺陷,将是控制源代码质量的重要指标,这个时候一个 ...