Description

Bessie and her sister Elsie want to travel from the barn to their favorite field, such that they leave at exactly the same time from the barn, and also arrive at exactly the same time at their favorite field. The farm is a collection of N fields (1 <= N <= 100) numbered 1..N, where field 1 contains the barn and field N is the favorite field. The farm is built on the side of a hill, with field X being higher in elevation than field Y if X < Y. An assortment of M paths connect pairs of fields. However, since each path is rather steep, it can only be followed in a downhill direction. For example, a path connecting field 5 with field 8 could be followed in the 5 -> 8 direction but not the other way, since this would be uphill. Each pair of fields is connected by at most one path, so M <= N(N-1)/2. It might take Bessie and Elsie different amounts of time to follow a path; for example, Bessie might take 10 units of time, and Elsie 20. Moreover, Bessie and Elsie only consume time when traveling on paths between fields -- since they are in a hurry, they always travel through a field in essentially zero time, never waiting around anywhere. Please help determine the shortest amount of time Bessie and Elsie must take in order to reach their favorite field at exactly the same moment.
给出一个n个点m条边的有向无环图,每条边两个边权。 
n<=100,没有重边。 
然后要求两条长度相同且尽量短的路径, 
路径1采用第一种边权,路径2采用第二种边权。 
没有则输出”IMPOSSIBLE”

Input

The first input line contains N and M, separated by a space. Each of the following M lines describes a path using four integers A B C D, where A and B (with A < B) are the fields connected by the path, C is the time required for Bessie to follow the path, and D is the time required for Elsie to follow the path. Both C and D are in the range 1..100.

Output

A single integer, giving the minimum time required for Bessie and Elsie to travel to their favorite field and arrive at the same moment. If this is impossible, or if there is no way for Bessie or Elsie to reach the favorite field at all, output the word IMPOSSIBLE on a single line.

Sample Input

3 3
1 3 1 2
1 2 1 2
2 3 1 2

Sample Output

2

SOLUTION NOTES:

Bessie is twice as fast as Elsie on each path, but if Bessie takes the
path 1->2->3 and Elsie takes the path 1->3 they will arrive at the
same time.

 
f[i][j]、g[i][j]表示用第一种/第二种边权到达i号点,当前费用为j的状态是否存在
这样i是100的,因为边权100所以费用是1w的,转移再100就爆了
但是因为只要存个真假所以直接上bitset
bitset大法好啊
 #include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define inf 0x7fffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
bitset <> f[];
bitset <> g[];
bool mrk[][];
int ga[][];
int gb[][];
int n,m;
int main()
{
n=read();m=read();
for (int i=;i<=m;i++)
{
int x=read(),y=read();
mrk[x][y]=;
ga[x][y]=read();gb[x][y]=read();
}
f[][]=;g[][]=;
for (int i=;i<=n;i++)
for (int j=;j<i;j++)
if (mrk[j][i])
{
int x=ga[j][i],y=gb[j][i];
f[i]|=(f[j]<<x);
g[i]|=(g[j]<<y);
}
for (int i=;i<=;i++)
{
if (f[n][i]&&g[n][i])
{
printf("%d\n",i);
return ;
}
}
printf("IMPOSSIBLE\n");
return ;
}

bzoj3890

bzoj3890 [Usaco2015 Jan]Meeting Time的更多相关文章

  1. 3890: [Usaco2015 Jan]Meeting Time( dp )

    简单的拓扑图dp.. A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了 时间复杂度O(m) --------------------------- ...

  2. BZOJ 3890 [Usaco2015 Jan]Meeting Time:拓扑图dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3890 题意: 给你一个有向图,n个点(n <= 100),m条边. 且所有的边都是从 ...

  3. [补档][Usaco2015 Jan]Grass Cownoisseur

    [Usaco2015 Jan]Grass Cownoisseur 题目 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过? (一个点在路 ...

  4. BZOJ3887 [Usaco2015 Jan] Grass Cownoisseur 【tarjan】【DP】*

    BZOJ3887 [Usaco2015 Jan] Grass Cownoisseur Description In an effort to better manage the grazing pat ...

  5. bzoj3887: [Usaco2015 Jan]Grass Cownoisseur

    题意: 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在路径中无论出现多少正整数次对答案的贡献均为1) =>有向图我们 ...

  6. BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP

    BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP Description In an effort to better manage t ...

  7. [bzoj3887][Usaco2015 Jan]Grass Cownoisseur_trajan_拓扑排序_拓扑序dp

    [Usaco2015 Jan]Grass Cownoisseur 题目大意:给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过?(一个点在 ...

  8. BZOJ3886 : [Usaco2015 Jan]Moovie Mooving

    f[i]表示用i集合内的电影可以达到的最长时间 f[i]向f[i|(1<<j)]更新,此时的时间为第j部电影在f[i]前的最晚上映时间 先排序一遍离散化后用前缀最大值解决 时间复杂度$O( ...

  9. BZOJ3888 [Usaco2015 Jan]Stampede

    我们只要把每头牛开始遮挡视线和结束遮挡视线的时间点都搞出来就好= = 再按照y轴排序...然后变成线段覆盖了..线段树搞一下就好了? /******************************** ...

随机推荐

  1. Meth | phpstorm invalid descendent file name

     Failed to collect files: Invalid descendent file name "codelog_ddz.\"(]))\",\').txt& ...

  2. codevs愚蠢的矿工(树形DP)

    /* 树形DP 根节点一定有人 然后 剩下的人没到每个孩子去 因为孩子数可能很多 不好枚举 所以转二叉树 分两部分 O(sum)就可以了 当然 转二叉树候必须顾及原来树的一些性质 如不能只选左孩子 转 ...

  3. win7/win8 64位系统注册TeeChart8.ocx 控件---以及dllregisterserver调用失败问题解决办法

    TeeChart控件就不多介绍了,很多朋友不知道开始怎么注册使用,尤其是在64位系统下如何注册的问题,具体如下: win7.win8  64位系统问题所在: 64位的系统一般都是可以安装32位程序的 ...

  4. Filter过滤器实现同一地址手机和电脑页面不同

    最近做一个网站,客户要求在访问主域名的时候实现电脑访问时展示电脑页面,手机访问时展示h5的手机页面,这种需求的使用还是比较多的:尤其网站需要百度推广的时候,百度推广就要求同一域名下,手机访问时展示手机 ...

  5. jQuery绑定事件的四种基本方式

    Query中提供了四种事件监听方式,分别是bind.live.delegate.on,对应的解除监听的函数分别是unbind.die.undelegate.off. bind(type,[data], ...

  6. ASP.NET的WebConfig

    转:http://blog.csdn.net/q3498233/article/details/8137364 WebConfig 花了点时间整理了一下ASP.NET Web.config配置文件的基 ...

  7. protocol buffer使用简介

    之前在工作中用到了protocol buffer(此处简称PB)(主要对数据进行序列化与反序列化,方便网络传输中的编解码),之后发现这是一个好东西,在此稍微记录下该工具如何使用,方便以后查阅 官网地址 ...

  8. Cacti添加threshold、monitor和setting

    Cacti版本:Version 0.8.8b 一.插件介绍: monitor:通过简单明了的图标提供服务器的运行状态 settings:给不同的插件提供一些共用的信息,如邮件信息,dns信息thold ...

  9. [转载]__type_traits

    在STL中为了提供通用的操作而又不损失效率,我们用到了一种特殊的技巧,叫traits编程技巧.具体的来说,traits就是 通过定义一些结构体或类,并利用模板类特化和偏特化的能力,给类型赋予一些特性, ...

  10. 交叉编译:cannot find /lib/libc.so.6 collect2: ld returned 1 exit status

    1.有时候明明指定了交叉编译的动态库搜索路径,但有些库提示还是搜索不到,而且提示的搜索路径有点奇怪,不是指定的路径,比如: /opt/mips-4.4/bin/../lib/gcc/mips-linu ...