#include #include #include #include #include #include #include #include #include #include using namespace std; class Graph { public: vector < vector > Adj; vector Paths; vector Incident; long long Num_Paths(int from, int to); }; long long Graph::Num_Paths(int from, int to) { long long rv; int tn; int i; if (from == to) return Paths[from]; rv = 0; for (i = 0; i < Adj[from].size(); i++) { tn = Adj[from][i]; Paths[tn] += Paths[from]; Incident[tn]--; if (Incident[tn] == 0) rv = Num_Paths(tn, to); } return rv; } int main() { Graph G; int N; int from, to; int i; cin >> N; G.Adj.resize(N); G.Paths.resize(N, 0); G.Paths[0] = 1; G.Incident.resize(N, 0); while (cin >> from >> to) { G.Adj[from].push_back(to); G.Incident[to]++; } cout << G.Num_Paths(0, N-1) << endl; exit(0); }