Problem Solving: The topic just seems to be a graph theory, but the subject is the DP thought of the investigation. Defines two arrays Dp[i],g[i] indicates the maximum number of forward edges at which the edge is numbered I, and when the point is I. The transfer equation is:
If the edge rights are different: Dp[i]=g[e[i].st]+1,g[e[i].en]=max (G[e[i].en],dp[i]).
If the edge rights are the same: {i,i+1,i+2,i+3 ...} Edges in the collection are numbered with the same edge.
Dp[i]=g[e[i].st]+1,dp[i+1]=g[e[i+1].st]+1,etc ...
G[e[i].en]=dp[i],g[e[i+1].en]=dp[i+1],etc ...
for the same side of the same situation, the first set of examples can see the problem, here the operation of the seniors said is the delay, specifically should be the point of delay, on the edge ahead.
#include <bits/stdc++.h>using namespace Std;const int maxe=1e5+10;struct edge{int st,en; int Val;} E[maxe];int dp[maxe],g[maxe];int inf=1e9;bool cmp (Edge A,edge b) {return a.val<b.val;} void solve (int n,int m) {memset (dp,0,sizeof (DP)); memset (G,0,sizeof (g)); for (int i=0;i<m;i++) {if (e[i].val<e[i+1].val) {dp[i]=g[e[i].st]+1; G[e[i].en]=max (G[e[i].en],dp[i]); }else{int j,t=i; for (j=i;j<m;j++) {if (e[j].val!=e[j+1].val) break; } i=j; for (int k=t;k<=j;k++) {dp[k]=g[e[k].st]+1; } for (int k=t;k<=j;k++) {G[e[k].en]=max (g[e[k].en],dp[k]); }}}} int max_e=0;//for (int i=1;i<=n;i++) {//Traversal point and edge should be the same effect, but the test data in the background is ... if (g[i]>max_e) {//max_e=g[i];//}//} for (int i=0;i<m;i++) {if (max_ E<dp[i]) { Max_e=dp[i]; }} printf ("%d\n", max_e);} int main () {freopen ("In.txt", "R", stdin); Freopen ("OUT1.txt", "w", stdout); int n,m; while (scanf ("%d%d", &n,&m)!=eof) {for (int i=0;i<m;i++) {scanf ("%d%d%d", &e[i].st,&e[i]. En,&e[i].val); } sort (e,e+m,cmp); E[m].val=inf; Solve (n,m); } return 0;}