codeforces721C
Journey
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 ≤ n ≤ 5000, 1 ≤ m ≤ 5000, 1 ≤ T ≤ 109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ ti ≤ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 ≤ k ≤ n) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
4 3 13
1 2 5
2 3 7
2 4 8
3
1 2 4
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
4
1 2 4 6
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
3
1 3 5 sol:十分裸的在DAG上dp,dp[i][j]表示到i节点,经过了j个点的最小距离。明明可以好好拓扑的,然后第一次脑抽了以为dfs就可以了,T了一发之后发现那是nm2的,好好tuopu即可AC
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,T;
namespace Pic
{
int tot=,Next[N],to[N],val[N],head[N],Indeg[N];
inline void add(int x,int y,int z)
{
Indeg[y]++;
Next[++tot]=head[x];
to[tot]=y;
val[tot]=z;
head[x]=tot;
}
int dp[N][N],Path[N][N];
inline void OutPut(int x,int Num)
{
if(Num==)
{
W(x); return;
}
OutPut(Path[x][Num],Num-);
W(x);
}
queue<int>Queue;
inline void Solve()
{
int i,j;
memset(dp,,sizeof dp);
dp[][]=;
Queue.push();
for(i=;i<=n;i++) if(Indeg[i]==)
{
for(j=head[i];j;j=Next[j]) Indeg[to[j]]--;
}
while(!Queue.empty())
{
int x=Queue.front(); Queue.pop();
for(i=head[x];i;i=Next[i])
{
if(!(--Indeg[to[i]])) Queue.push(to[i]);
for(j=;j<n;j++) if(dp[to[i]][j+]>dp[x][j]+val[i])
{
dp[to[i]][j+]=dp[x][j]+val[i];
Path[to[i]][j+]=x;
}
}
}
for(i=n;i>=;i--) if(dp[n][i]<=T)
{
Wl(i); OutPut(n,i); break;
}
}
}
int main()
{
int i;
R(n); R(m); R(T);
for(i=;i<=m;i++)
{
int x,y,z;
R(x); R(y); R(z);
Pic::add(x,y,z);
}
Pic::Solve();
return ;
}
/*
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4 Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6 Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5 input
4 4 10
2 1 1
2 3 1
1 3 1
3 4 1
output
3
1 3 4
*/
codeforces721C的更多相关文章
- Codeforces 刷水记录
Codeforces-566F 题目大意:给出一个有序数列a,这个数列中每两个数,如果满足一个数能整除另一个数,则这两个数中间是有一条边的,现在有这样的图,求最大联通子图. 题解:并不需要把图搞出来, ...
- CodeForces-721C-Journey(DAG, DP)
链接: https://vjudge.net/problem/CodeForces-721C 题意: Recently Irina arrived to one of the most famous ...
随机推荐
- alfs学习笔记-自动化构建lfs系统
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一名linux爱好者,记录构建Linux From Scratch的过程 经博客园-骏马金龙前辈介绍,开始接触学习lfs,用博客 ...
- vue的项目结构记录
vue的项目结构 不知道大家有没这样的情况,面对刚配置好的脚手架,创建的文件不知道该放哪个文件下,导致后面开发一些文件不好找,不利于维护. 接下来我说说我项目中的一些文件: 首先是components ...
- wordcloud2.js
https://blogs.msdn.microsoft.com/dotnet/2019/01/10/announcing-ml-net-0-9-machine-learning-for-net/ h ...
- DIV+CSS初学随记
字间隔word-spacing 属性可以改变字(单词)之间的标准间隔.其默认值 normal 与设置值为 0 是一样的. word-spacing 属性接受一个正长度值或负长度值.如果提供一个正长度值 ...
- Fragment已经被added了导致的异常。
java.lang.IllegalStateException: Fragment already added: ******Effect 出现的原因是commit方法提交是异步的,所以容易出现,判 ...
- (详细)华为荣耀V10 BKL-AL00的USB调试模式在哪里打开的步骤
每当我们使用pc连接安卓手机的时候,如果手机没有开启Usb开发者调试模式,pc则无法成功检测到我们的手机,有时我们使用的一些功能比较强的的app比如以前我们使用的一个app引号精灵,老版本就需要开启U ...
- dede后台删除文章后台还有分页显示解决方法
打开dede目录中content_list.php 大概在100行左右 $sql = "SELECT COUNT(*) AS dd FROM `#@__arctiny` $tinyQuery ...
- adb部署及使用
一 掌握adb部署&使用方法及常用命令 1.何为adb? sdk软件开发套件software development kit apk是安卓应用安装包 adb是android sdk的一个工具, ...
- 详解MongoDB中的多表关联查询($lookup)
一. 聚合框架 聚合框架是MongoDB的高级查询语言,它允许我们通过转换和合并多个文档中的数据来生成新的单个文档中不存在的信息. 聚合管道操作主要包含下面几个部分: 命令 功能描述 $projec ...
- Linux(Deepin 15.9) - MySQL5.7 安装
Linux(Deepin 15.9) - MySQL5.7 安装 sudo apt install mysql-server/panda sudo apt install mysql-client/p ...