World Exhibition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1383    Accepted Submission(s):
679

Problem Description
Nowadays, many people want to go to Shanghai to visit
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.

 
Input
First line: An integer T represents the case of
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.

 
Output
For each line: A single integer. If no line-up is
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.
 
Sample Input
1
4 2 1
1 3 8
2 4 15
2 3 4
 
Sample Output
19
 
题意跟 poj3169  一模一样:分析点我!!!!
#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的更多相关文章

  1. 【HDOJ】3592 World Exhibition

    基础差分约束. /* 3592 */ #include <iostream> #include <algorithm> #include <queue> #incl ...

  2. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  6. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  7. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  8. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

  9. POJ2184 Cow Exhibition[DP 状态负值]

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12420   Accepted: 4964 D ...

随机推荐

  1. [转]利用maven的surefire插件实现单元测试与集成测试

    原文链接 http://my.oschina.net/dlpinghailinfeng/blog/301136 maven单元测试与集成测试 通过maven的Profile 配置生命周期 通过mave ...

  2. html标签data大写获取不到值:只能小写+横杠命名

    html标签data大写获取不到值:只能小写+横杠命名 例如: <i class="glyphicon glyphicon-question-sign" data-tip-t ...

  3. phpcms V9 添加模块(转)

    转自:http://www.cnblogs.com/Braveliu/p/5101345.html 为phpcms创建一个模块的开发流程 [1]创建模块目录 通过前面的学习,我们已经知道phpcms ...

  4. 怎样清除td和input之间空隙

    <style> input {background:red;border:none;height:30px;margin:0px} td {background-color:blue;pa ...

  5. lucene解决全文检索word2003,word2007的办法

    在上一篇文章中 ,lucene只能全文检索word2003,无法检索2007,并且只能加载部分内容,无法加载全文内容.为解决此问题,找到了如下方法 POI 读取word (word 2003 和 wo ...

  6. Xcode7.01相对于底版本的变动小结

    1.在Xcode7中系统不再自动支持http请求,需要配置plist才能使用http: 2.appdelegate中的self.window不再支持直接往window上加view,必须先给window ...

  7. Android 自定义RadioButton实现

    由于使用小米系统MIUI运行是RadioButton样式跟google Android API自定义的不一样,则我们可以定义任何想要的东东.没有做不到,只有想不到 Android 自定义RadioBu ...

  8. int 占一个机器字长

    int与short int是不一样的. C++标准规定,int占一个机器字长.在32位系统中int占32位,也就是4个字节, 而在老式的16位系统中,int占16位,即2个字节. 而C++标准中只限制 ...

  9. bzoj 2806: [Ctsc2012]Cheat 后缀自动机DP

    2806: [Ctsc2012]Cheat Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 583  Solved: 330[Submit][Statu ...

  10. Myeclipse2013 SVN安装方法以及项目上传到svn服务器

    1. 打开 Myeclipse 工具栏下的Help下的Install from Site 2.打开后弹出窗口, 并点击Add标签,如下图: 3.现在是最重要的一步,填写相关信息. 在对话框Name输入 ...