#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct ST{ int X, Y, Z; }; template class SCC { vector G[MAX_V]; vector rG[MAX_V]; vector vs; bool used[MAX_V]; int V; vector cmp; void dfs(int v){ used[v] = true; for(int i=0; i get_edge(int from){ return G[from]; } vector get_cmp(){ return cmp; } void add_edge(int from, int to){ G[from].push_back(to); rG[to].push_back(from); } int calc(){ for(int i=0; i=0; i--) if(!used[vs[i]]) rdfs(vs[i], k++); return k; } vector depth(){ vector> order; vector dp(V, 1); calc(); for(int i=0; i> N; vector v; rep(i,N){ int X, Y, Z; cin >> X >> Y >> Z; v.push_back((ST){X,Y,Z}); } SCC<1005> scc(N); rep(i,N){ rep(j,N){ if(i == j) continue; if(can_in(v[i], v[j])){ scc.add_edge(i,j); } } } vector dp = scc.depth(); int ret = 0; rep(i,dp.size()){ ret = max(ret, dp[i]); } cout << ret << endl; return 0; }