技不如人甘拜下风
这题网上说法有 建反向边和先拓扑
都是为了每个点之前将其前驱都遍历到

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 5005;
const int INF = 0x3f3f3f3f; int N,M,T;
vector<pair<int,int> > mp[MAXN];
ll dp[MAXN][MAXN];
int vis[MAXN];
int ans;
vector<int> op;
void dfs(int x) {
if(vis[x]) return;
for(int i = 0; i < (int)mp[x].size(); ++i) {
int y = mp[x][i].first;
if(!vis[y]) dfs(y);
}
for(int i = 0; i < (int)mp[x].size(); ++i) {
int y = mp[x][i].first; int z = mp[x][i].second;
for(int j = 1; j <= N; ++j) {
if( dp[x][j] > dp[y][j-1]+z ) {
dp[x][j] = dp[y][j-1]+z;
if(x==N && j > ans && dp[x][j] <= T) ans = j;
}
}
}
vis[x] = 1;
}
void re_dfs(int x,int num) {
op.push_back(x);
for(int i = 0; i < (int)mp[x].size(); ++i) {
int y = mp[x][i].first; int z = mp[x][i].second;
if(dp[x][num] == dp[y][num-1]+z){
re_dfs(y,num-1);
return;
}
}
}
int main(){
while(~scanf("%d %d %d",&N,&M,&T)) {
ans = 0; op.clear();
memset(vis,0,sizeof(vis));
memset(dp,INF,sizeof(dp));
for(int i = 1; i <= N; ++i) mp[i].clear();
for(int i = 1; i <= M; ++i) {
int a,b,c; scanf("%d %d %d",&a,&b,&c);
mp[b].push_back({a,c});
}
dp[1][1] = 0;
dfs(N);
re_dfs(N,ans);
printf("%d\n",ans);
for(int i = (int)op.size()-1; i >= 0; --i) {
printf("%d ",op[i]);
} printf("\n");
}
return 0;
}

CF374 Journey的更多相关文章

  1. CF721C. Journey[DP DAG]

    C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input ou ...

  2. POJ2488A Knight's Journey[DFS]

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41936   Accepted: 14 ...

  3. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  4. POJ2488-A Knight's Journey(DFS+回溯)

    题目链接:http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  5. codeforces 721C C. Journey(dp)

    题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  6. A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏

    A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...

  7. HDOJ-三部曲一(搜索、数学)- A Knight's Journey

    A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) ...

  8. 【推公式】UVa 10995 - Educational Journey

    1A~,但后来看人家的代码好像又写臭了,T^T... Problem A: Educational journey The University of Calgary team qualified f ...

  9. poj 3544 Journey with Pigs

    Journey with Pigs Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3004   Accepted: 922 ...

随机推荐

  1. 有标号DAG计数 [容斥原理 子集反演 组合数学 fft]

    有标号DAG计数 题目在COGS上 [HZOI 2015]有标号的DAG计数 I [HZOI 2015] 有标号的DAG计数 II [HZOI 2015]有标号的DAG计数 III I 求n个点的DA ...

  2. BZOJ 4513: [Sdoi2016]储能表 [数位DP !]

    4513: [Sdoi2016]储能表 题意:求\[ \sum_{i=0}^{n-1}\sum_{j=0}^{m-1} max((i\oplus j)-k,0) \] 写出来好开心啊...虽然思路不完 ...

  3. HDU 2141 Can you find it? [二分]

    Can you find it? Give you three sequences of numbers A, B, C, then we give you a number X. Now you n ...

  4. ArcGIS API for JavaScript开发环境搭建与发布以及基本功能实现

    1.背景介绍 ArcGIS API for JavaScript 咱这就不介绍了,具体可看ESRI中国的介绍:http://support.esrichina.com.cn/2011/0223/960 ...

  5. (python功能定制)复杂的xml文件对比,产生HTML展示区别

    功能的设计初衷: 处理复杂的xml对比,屏蔽同节点先后顺序的影响 主要涉及知识点: 1.xml解析 ------- ElementTree库 2.文件比对差别 ------- difflib库 3.获 ...

  6. 新版Azure Automation Account 浅析(三) --- 用Runbook管理AAD Application Key

    新版Azure Automation Account 浅析(三) --- 用Runbook管理AAD应用的Key 前篇讲过有一个面向公众的Runbook库,社区和微软一直往其中加入新的Runbook, ...

  7. HAProxy+Nginx 负载均衡

    一.什么是HAProxy HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点, ...

  8. 浅显总结ASCII Unicode UTF-8的区别

    如果觉得此地排版不好,欢迎访问我的博客 浅显总结ASCII Unicode UTF-8的区别 制作表单时,为了追求更好的用户交互体验,常常会有提示性的内容,比如提醒用户字符的限制.由于英文,中文字符的 ...

  9. 修改MacBook Pro主机名,共享电脑名

    https://support.apple.com/kb/PH25384?viewlocale=zh_CN&locale=zh_CN http://www.ituring.com.cn/art ...

  10. Nginx 静态资源缓存设置

    在开发调试web的时候,经常会碰到因浏览器缓存(cache)而经常要去清空缓存或者强制刷新来测试的烦恼,提供下apache不缓存配置和nginx不缓存配置的设置.在常用的缓存设置里面有两种方式,都是使 ...