#include #include #include #include using namespace std; class Node { public: int pos, chg, cost; Node(int pos, int chg, int cost) : pos(pos), chg(chg), cost(cost) {} bool operator < (const Node &nd) const { return cost > nd.cost; } }; int main(){ int n, m, c; ifstream fin("G.in"); static int len[100][100]; while(fin >> n >> m >> c, n){ vector< vector< pair > > g(n); for(int i=0;i> f >> t >> c; g[f-1].push_back(make_pair(t-1, c)); } for(int i=0;i qu; qu.push(Node(0, 0, 0)); len[0][0] = 0; while(!qu.empty()){ Node nd = qu.top(); qu.pop(); int pos = nd.pos, chg = nd.chg, cost = nd.cost; if(len[pos][chg] < cost) continue; for(int i=0;i len[pos][chg]+g[pos][i].second){ len[next][chg] = len[pos][chg]+g[pos][i].second; qu.push(Node(next, chg, len[next][chg])); } if(chg+1 < n && len[next][chg+1] > len[pos][chg]){ len[next][chg+1] = len[pos][chg]; qu.push(Node(next, chg+1, len[next][chg+1])); } } } for(int i=1;i