Last active
October 18, 2015 18:06
-
-
Save jo32/5ef6f2bd1c750fd9c8ab to your computer and use it in GitHub Desktop.
CODEFORCE 459E
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#define MAX 300007 | |
using namespace std; | |
struct Edge { | |
int u; | |
int v; | |
int w; | |
} e[MAX]; | |
bool cmp(Edge& a, Edge& b) | |
{ | |
return a.w < b.w; | |
} | |
int dp[MAX]; | |
int g[MAX]; | |
int n; | |
int m; | |
int main() | |
{ | |
scanf("%d%d", &n, &m); | |
for (int i = 0; i < m; i++) { | |
scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w); | |
} | |
sort(e, e + m, cmp); | |
int t = 0; | |
int ans = 0; | |
e[m].w = -1; | |
for (int i = 0; i < m; i++) { | |
dp[i] = g[e[i].u] + 1; | |
if (e[i].w != e[i + 1].w) { | |
for (int j = t; j <= i; j++) { | |
g[e[j].v] = max(g[e[j].v], dp[j]); | |
} | |
t = i + 1; | |
} | |
ans = max(ans, dp[i]); | |
} | |
printf("%d\n", ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment