题目描述

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: (file meeting.in)

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 (file meeting.out)

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.

输入输出样例

输入样例#1:

3 3
1 3 1 2
1 2 1 2
2 3 1 2
输出样例#1:

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.

 dp[i][j],i表示点i,j表示权值大小。

bool型,如果为true表示该点可以在该时间到达,反之不行。
遍历从第一个点开始能到达的所有的点,能的话为ture ,遍历dp[n][1……10000]是否可以满足两个dp同时为真,不
能为impossible,因为每条边最多是100,从第一个点走到最后一个点最多有100条边,所以一定是小于10000的

#include<iostream>
#include<cstdio> const int N=;
bool dp[][N];
bool dp2[][N]; struct node {
int v,next,w1,w2;
}edge[N];
int num,head[N];
void add_edge(int u,int v,int w1,int w2)
{
edge[++num].v=v;edge[num].w1=w1;edge[num].w2=w2;edge[num].next=head[u];head[u]=num;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int u,v,a1,a2;
for(int i=;i<=m;i++)
{
scanf("%d%d%d%d",&u,&v,&a1,&a2);
add_edge(u,v,a1,a2);
}
dp[][]=dp2[][]=;
for(int i=;i<=n;i++)
{
for(int j=head[i];j;j=edge[j].next)
{
int v=edge[j].v;
for(int k=edge[j].w1;k<=;k++)
dp[v][k]|=dp[i][k-edge[j].w1];
for(int k=edge[j].w2;k<=;k++)
dp2[v][k]|=dp2[i][k-edge[j].w2];
}
}
for(int i=;i<=;i++)
if(dp[n][i]&&dp2[n][i])
{
printf("%d\n",i);
return ;
}
printf("IMPOSSIBLE\n");
return ;
}

luogu P3116 [USACO15JAN]会议时间Meeting Time的更多相关文章

  1. P3116 [USACO15JAN]会议时间Meeting Time

    P3116 [USACO15JAN]会议时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...

  2. 洛谷P3116 [USACO15JAN]约会时间Meeting Time

    P3116 [USACO15JAN]约会时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...

  3. #使用parser获取图片信息,输出Python官网发布的会议时间、名称和地点。

    # !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib ...

  4. 【Luogu】P3116会议时间(拓扑排序,DP)

    题目链接 本题使用拓扑排序来规划DP顺序.设s[i][j]表示i步是否能走到j这个点,e[i][j]表示i步是否能走到j这个点——用第二条路径.因为要满足无后效性和正确性,只有第i个点已经全部更新完毕 ...

  5. [Luogu P3626] [APIO2009] 会议中心

    题面 传送门:https://www.luogu.org/problemnew/show/P3626 Solution 如果题目只要求求出第一问,那这题显然就是大水题. 但是加上第二问的话...... ...

  6. Luogu 3626 [APIO2009]会议中心

    很优美的解法. 推荐大佬博客 如果没有保证字典序最小这一个要求,这题就是一个水题了,但是要保证字典序最小,然后我就不会了…… 如果一条线段能放入一个区间$[l', r']$并且不影响最优答案,那么对于 ...

  7. [Luogu P3119] [USACO15JAN]草鉴定Grass Cownoisseur (缩点+图上DP)

    题面 传送门:https://www.luogu.org/problemnew/show/P3119 Solution 这题显然要先把缩点做了. 然后我们就可以考虑如何处理走反向边的问题. 像我这样的 ...

  8. Luogu 3119 [USACO15JAN]草鉴定Grass Cownoisseur

    思路很乱,写个博客理一理. 缩点 + dp. 首先发现把一个环上的边反向是意义不大的,这样子不但不好算,而且相当于浪费了一次反向的机会.反正一个强连通分量里的点绕一遍都可以走到,所以我们缩点之后把一个 ...

  9. luogu P3119 [USACO15JAN]草鉴定Grass Cownoisseur

    题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-w ...

随机推荐

  1. hdu5319 简单模拟

    题意很好懂,大致就是三种颜色,红和蓝一起会变绿,给个终态矩阵,问从原始状态到终态最少画几笔?  按一定规则画 思路就是记红为1,蓝为2,绿为3,先遍历绿色,针对每一块绿色进行删除,每找到一块绿色,首先 ...

  2. Redis实现之字符串

    简单动态字符串 Redis中的字符串并不是传统的C语言字符串(即字符数组,以下简称C字符串),而是自己构建了一种简单动态字符串(simple dynamic string,SDS),并将SDS作为Re ...

  3. cf965e Short Code

    ref #include <algorithm> #include <iostream> #include <cstring> #include <cstdi ...

  4. C#实现eval 进行四则运算(有码)

    在JavaScript中实现四则运算很简单,只需要调用eval函数就行了,但是不知道什么原因万能的.NET却没有封装这个函数~ 在这里为大家封装了一个C#版本的eval函数,具体的设计参考了<大 ...

  5. 【Combination Sum 】cpp

    题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C  ...

  6. 对CRC32的小结加上bugku一道题目:好多压缩包

    CRC32就是校验值,一般来说不同的文件校验值不一样,所以我们可以挨个爆破,当然这是在文件比较小的时候.下面是几种情形. 1. 我新建了一个flag.txt文档,里面是我的生日20180818 然后我 ...

  7. windows批处理 打开exe后关闭cmd

    start "" "程序路径.exe"    这样调用就OK啦.如: start "" "D:\123.exe" 如果下 ...

  8. 精通CSS高级Web标准解决方案(4、对链接应用样式)

    4.1 简单的链接样式 锚可以作为内部引用,也可以作为外部链接,应该区分对待. 伪类选择器: :link 用来寻找没有访问过的链接 :visited 用来寻找已经访问过的链接 a:link{color ...

  9. PAT1022

    输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数. 输入格式: 输入在一行中依次给出3个整数A.B和D. 输出格式: 输出A+B的D ...

  10. 海拔(bzoj 2007)

    Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作一个 正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1) ...