#include #include #include #include #include using namespace std; const int big=9999; int main(){ ifstream cin("friday.in"); for(int n,m;cin >> n >> m,(n!=0 or m!=0);){ int ist,jst,exit; cin >> ist >> jst >> exit; ist--;jst--;exit--; vector > gi(n); vector > gj(n); for(int i=0;i> s >> d >> e; s--;d--; gi[s].push_back(d); gi[d].push_back(s); gj[s].push_back(d); if(e==0) gj[d].push_back(s); } multimap probes; probes.insert(make_pair(0,jst)); vector jcost(n,big); while(!probes.empty()){ int cost = probes.begin()->first; int pos = probes.begin()->second; probes.erase(probes.begin()); if(cost < jcost[pos]){ jcost[pos]=cost; for(int k=0;k icost(n,big); while(!probes.empty()){ int cost = probes.begin()->first; int pos = probes.begin()->second; probes.erase(probes.begin()); if(cost < icost[pos] && (cost <=jcost[pos] || pos != ambush_pos)){ icost[pos]=cost; for(int k=0;k