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 ...
随机推荐
- JavaScript实现url地址自动检测并添加URL链接示例代码
写一个简单的聊天系统,发出Htpp的Url实现跳转加上a标签,下面是具体的实现,感兴趣的朋友不要错过 背景:写一个简单的聊天系统,发出Htpp的Url实现跳转加上a标签. 实现代码: 复制代码代码如 ...
- linux mysql字符编码问题
发布:thatboy 来源:脚本学堂 [大 中 小] 本文介绍下,linux环境中mysql字符编码问题的解决办法,有遇到mysql编码问题的朋友,可以参考下本文的介绍,希望对你有一定的帮 ...
- TDirectory.GetParent获取指定目录的父目录
使用函数: System.IOUtils.TDirectory.GetParent class function GetParent(const Path: string): string; stat ...
- 2016031401 - ubuntu显示桌面快捷键
ubuntu显示桌面快捷键设置 步骤如下:系统设置->键盘->快捷键->窗口->最小化窗口 个人设置的是super+D,super就是window下的win键.
- sqlserver access 多数据库操作
今天搞了一天的事情, 更新 ACCESS 數據庫 ,要從 SQL SERVER 2008數據庫中 查詢資料.沒找到資料 只能自己做了. 首先查找一下 ,如何 用SQL 語句 select * ...
- (转) 各种好用的插件 Xcode
时间就是金钱.编码效率的提升意味着更多的收入.可是当我们的开发技巧已经到达一定高度时,如何让开发效率更上一层楼呢?答案就是使用开发工具!在这篇文章中,我会向你介绍一些帮助我提升编码速度和工作效率的工具 ...
- 提交App Store注意事项1
1.未遵守苹果iOS APP数据储存指导方针. 如果你的App有离线数据下载功能,尤其需要关注这一点.因为离线数据一般占用存储空间比较大,可以被重新下载和重建,但是用户往往希望系统存储空间紧时也依然能 ...
- log的6种等级
在Java中,log有6种等级,从低到高为: (1)TRACE:用于展现程序执行的轨迹 (2)DEBUG:用于协助低层次的调试 (3)INFO:用于基本高层次的诊断信息,在长时间运行的代码段开始运行及 ...
- 关于textjs的tree带复选框的树
通过查阅一些资料和自己之前了解到的一些相关知识,有时项目中需要用到.话不多说,先看一下效果图: 我写的这人员选择的树,主要是改写了TreePanel,如下代码: ExtendTreePanel.js ...
- 这是从word发的第一篇博客。
喜欢做的事,怎么样都不会厌倦. 以前只知道office功能强大,但不太清楚到底还能干些啥,印象最深的是outlook了,自己也在用,挺好 今天偶然发现,word还能发布博客,真是太惊喜了 这算是一篇实 ...