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 ...
随机推荐
- vivo如何录制手机视频 分享简单的操作方法
智能手机功能不断的发展更新,手机已经普及到每一个人,在日常的生活或者工作中都离不开手机,手机中的功能例如一些小视频软件都是非常有趣的,vivo如何录制手机视频?下面我们一起来看看吧! 使用工具:手机 ...
- image_channel_data_type含义
在穿件image对象的时候,需要传入一个cl_image_format参数,该参数结果包含image_channel_order和image_channel_data_type两个成员.前一个成员表示 ...
- 章节九、3-Desired Capabilities介绍
一.Desired Capabilities是selenium webdrive中已经写好的一个类,我们可以通过它来告诉selenium webdrive在Desired Capabilities是什 ...
- [Web][DreamweaverCS6][高中同学毕业分布去向网站+服务器上挂载]一、安装与破解DreamweaverCS6+基本规划
DreamweaverCS6安装与破解 一.背景介绍:同学毕业分布图项目计划简介 哎哎哎,炸么说呢,对于Web前端设计来说,纯手撕html部分代码实在是难受. 对于想做地图这类的就“必须”用这个老工具 ...
- 领域驱动设计(DDD:Domain-Driven Design)
领域驱动设计(DDD:Domain-Driven Design) Eric Evans的"Domain-Driven Design领域驱动设计"简称DDD,Evans DDD是一套 ...
- 第四篇 CSS
在标签上设置style属性: background-color:#2459a2: height:48px: ... 编写CSS样式: 如何注释:/* 或 */ 一. 在标签的属性中编写 <!DO ...
- Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和输入流 捕获sys.exit()调用 optparse argparse
Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和 ...
- webmagic 爬取网页所有文章的标题时间作者和内容
package com.ij34; import us.codecraft.webmagic.Site; import us.codecraft.webmagic.Page; import us.co ...
- Asp.net mvc 项目返回Json
因mvc控制器返回类型JsonResult 在处理对象转JSON的时候,对日期的格式化处理并不太符合要求,所以重新继承抽象类ActionResult使用Newtonsoft.Json来系列化 usin ...
- sqlbulkcopy 批量插入数据
批量插入 Datetable数据 通过sqlbulkcopy 插入1百万条数据 用时 10秒钟 (有兴趣的小伙伴可以去测试) /// <summary> /// /// </sum ...