#include #include using namespace std; typedef long long ll; ll cost[110][110]; vector from[110], to[110]; vector memo[110]; vector func(int k, int n) { if (memo[k].size()) return memo[k]; vector res(n); if (from[k].empty()) { res[k]=1; return res; } for(int v: from[k]) { auto t=func(v, n); for(int i=0;i>n>>m) { for(int i=0;i>a>>c>>b; cost[--a][--b]=c; from[b].push_back(a); to[a].push_back(b); } auto res=func(n-1, n); for(int i=0;i