http://www.codeforces.com/problemset/problem/459/E

题意:

给出n个点,m条边的有向图,每个边有边权,求一条最长的边权上升的路径的长度。

思路:用f存边,g存点,然后排序转移,注意相同的要延迟转移

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
struct edge{
int u,v,w;
}e[];
int n,m,f[],g[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
bool cmp(edge a,edge b){
return a.w<b.w;
}
int main(){
n=read();m=read();
for (int i=;i<=m;i++){
e[i].u=read();e[i].v=read();e[i].w=read();
}
std::sort(e+,e++m,cmp);
int t=,ans=;
for (int i=;i<=m;i++){
f[i]=g[e[i].u]+;
if (e[i].w!=e[i+].w){
for (int j=t;j<=i;j++)
g[e[j].v]=std::max(g[e[j].v],f[j]);
t=i+;
}
ans=std::max(ans,f[i]);
}
printf("%d\n",ans);
return ;
}

Codeforces 459E Pashmak and Graph的更多相关文章

  1. Codeforces 459E Pashmak and Graph(dp+贪婪)

    题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...

  2. CodeForces - 459E Pashmak and Graph[贪心优化dp]

    E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces 459E Pashmak and Graph:dp + 贪心

    题目链接:http://codeforces.com/problemset/problem/459/E 题意: 给你一个有向图,每条边有边权. 让你找出一条路径,使得这条路径上的边权严格递增. 问你这 ...

  4. codeforces 459E E. Pashmak and Graph(dp+sort)

    题目链接: E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input st ...

  5. codeforces 459E

    codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...

  6. CF459E Pashmak and Graph (DP?

    Codeforces Round #261 (Div. 2) E - Pashmak and Graph E. Pashmak and Graph time limit per test 1 seco ...

  7. cf459E Pashmak and Graph

    E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

  9. ACM - 最短路 - CodeForces 295B Greg and Graph

    CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...

随机推荐

  1. 我学hash_map(1)

    本文来源:http://blog.chinaunix.net/uid-26548237-id-3800125.html  map是什么? map是键值对(key-value),复杂度是O(n).但是查 ...

  2. android SimpleCursorAdapter的使用

    String[] fields=new String[]{"foodname","price","taste","stuff&qu ...

  3. HDU3473--Minimum Sum(静态区间第k大)

    Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. ubantu14.04 apache2 支持重写模式

    想要开启thinkphp的重写模式,apache必须.htaccess支持, 其他情况也有需要开启.htaccess支持的. 下面是ubantu开启方法: 0. .htaccess这个文件应该放在与入 ...

  5. JS(五)

    感觉JS里面还是有很多小技巧的,知道套路了,其实实现起来其实也还没有想象中的那么复杂.不过我觉得还是要把所学的知识融会贯通吧,不能学了JS就忘了前面的知识,结合起来才会威力无穷. 1.跑马灯:弹弹弹 ...

  6. Heritrix源码分析(十四)

    近段时间在搞定Lucene的一些问题,所以Heritrix源码分析暂时告一段落.今天下午在群里有同学提到了Heritrix异常终止的问题以及让Heritrix不停的抓取(就是抓完一遍后载入种子继续抓取 ...

  7. 查询rman备份信息经常使用指令

    查询rman备份信息经常使用指令 ----登陆到rman $rman target / ----以精简的格式查看备份信息 RMAN> list backup of database summar ...

  8. Linux下的进程控制块——task_struct

    在Linux中具体实现PCB的是 task_struct数据结构,以下实现摘自github 我想说它真的很长很长...... ↓ struct task_struct { volatile long ...

  9. getClass 与getSimpleName

    //首先定义一个借口 package com.test; public interface Fruit { } //定义一个实现类 package com.test; public class App ...

  10. GCC下32位与64位机器类型变量所占字节数

    GCC下32位与64位机器类型变量所占字节数 在C语言中,编译器一般根据自身硬件针对类型变量来选择合适的字节大小,下面列举一下在GCC编译器下32位机器与64位机器各个类型变量所占字节数目: C语言 ...