#include #include #include #include using namespace std; long long g[200][200]; long long f[200][200]; int main(){ while(1){ int n, m; cin >> n >> m; if(!cin)break; for(int i=0;i> a >> b >> c; // g[a-1][b-1] = c; <- wrong orz g[a-1][b-1] += c; } while(1){ vector prev(m); deque path; for(int i=0;i q; q.push(0); while(!q.empty()){ int current = q.front(); q.pop(); if(current == m-1){ while(1){ path.push_front(current); if(current == 0)break; current = prev[current]; } break; } for(int i=0;i 0){ q.push(i); prev[i] = current; } } } if(path.size() == 0)break; long long mincost = 1<<30; for(int i=0;i