Codeforces Round #261 (Div. 2) E. Pashmak and Graph(DP)
程序员文章站
2022-06-04 09:54:00
...
题目链接
题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边。
思路:dp【i】代表前i条边能满足条件的最大长度,g【i】代表以i点为结尾的最大长度。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e5+1;
const int mod=1e9+7;
int dp[maxn],g[maxn],ans=1;
struct node{
int u,v,w,id;
}s[maxn];
bool cmp(const node &a,const node &b)
{
return a.w<b.w;
}
int main()
{
int n,m,u,v,w,j,t=1;
scanf("%d %d",&n,&m);
for(int i=1;i<=m;++i)
{
scanf("%d %d %d",&u,&v,&w);
s[i].u=u,s[i].v=v,s[i].w=w,s[i].id=i;
}
sort(s+1,s+1+m,cmp);
for(int i=1;i<=m;++i)
{
dp[i]=g[s[i].u]+1;
if(s[i].w!=s[i+1].w)
{
for(j=t;j<=i;++j)
g[s[j].v]=max(g[s[j].v],dp[j]);
t=i+1;
}
}
for(int i=1;i<=m;++i) ans=max(ans,dp[i]);
printf("%d\n",ans);
}
下一篇: 要这么埋汰
推荐阅读
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #670 (Div. 2) E. Deleting Numbers(交互,素数构造)
-
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution(多颗树状数组+思维)
-
Codeforces Round #658 (Div. 2) D. Unmerge(dp,01背包)
-
Codeforces Round #261 (Div. 2)[ABCDE]
-
Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)_html/css_WEB-ITnose
-
Codeforces Round #468 (Div. 2): F. Teodor is not a liar!(DP)
-
Codeforces Round #641 (Div. 2) E. Orac and Game of Life(bfs+思维)
-
Educational Codeforces Round 95 (Rated for Div. 2)C. Mortal Kombat Tower【dp】
-
Codeforces Round #277 (Div. 2)D(树形DP计数类)_html/css_WEB-ITnose