Codeforces 459E Pashmak and Graph

Posted GFY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 459E Pashmak and Graph相关的知识,希望对你有一定的参考价值。

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

题意:

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

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

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<iostream>
 6 struct edge{
 7     int u,v,w;
 8 }e[300005];
 9 int n,m,f[300005],g[300005];
10 int read(){
11     int t=0,f=1;char ch=getchar();
12     while (ch<0||ch>9){if (ch==-) f=-1;ch=getchar();}
13     while (0<=ch&&ch<=9){t=t*10+ch-0;ch=getchar();}
14     return t*f;
15 }
16 bool cmp(edge a,edge b){
17     return a.w<b.w;
18 }
19 int main(){
20     n=read();m=read();
21     for (int i=1;i<=m;i++){
22         e[i].u=read();e[i].v=read();e[i].w=read();
23     }
24     std::sort(e+1,e+1+m,cmp);
25     int t=1,ans=0;
26     for (int i=1;i<=m;i++){
27         f[i]=g[e[i].u]+1;
28         if (e[i].w!=e[i+1].w){
29             for (int j=t;j<=i;j++)
30              g[e[j].v]=std::max(g[e[j].v],f[j]);
31             t=i+1; 
32         }
33         ans=std::max(ans,f[i]);
34     }
35     printf("%d\n",ans);
36     return 0;
37 }

 

以上是关于Codeforces 459E Pashmak and Graph的主要内容,如果未能解决你的问题,请参考以下文章

CF459E Pashmak and Graph

Codeforces Round #261 (Div. 2)——Pashmak and Buses

CodeForces - 459E

[Codeforces Round #261 (Div. 2) E]Pashmak and Graph(Dp)

A. Pashmak and Garden1200 / 思维

Codeforcecs 459D Pashmak and Parmida's problem 树状数组 OR 分治