#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,M; cin >> N >> M; vector>> Graph(N); for(long long i=0; i> u >> v; u--; v--; long long w; cin >> w; Graph.at(u).push_back({v,i,-w}); Graph.at(v).push_back({u,i,w}); } vector already(N); vector dist(N,1e18); priority_queue,vector>,greater<>> Q; dist.at(0) = 0; Q.push({0,0}); long long start = -1; while(Q.size()){ auto [nowd,pos] = Q.top(); Q.pop(); if(nowd != dist.at(pos)) continue; if(already.at(pos)){start = pos; break;} already.at(pos) = true; for(auto [to,epos,w] : Graph.at(pos)){ if(dist.at(to) > dist.at(pos)+w){ dist.at(to) = dist.at(pos)+w; Q.push({dist.at(to),to}); } } } if(start == -1){cout << "-1\n"; return 0;} dist.assign(N,1e18); already.assign(N,false); dist.at(start) = 0; while(Q.size()) Q.pop(); Q.push({0,start}); vector> back(N); long long start2 = -1; vector route; vector first(N); while(Q.size()){ auto [nowd,pos] = Q.top(); Q.pop(); if(dist.at(pos) != nowd) continue; already.at(pos) = true; for(auto [to,epos,w] : Graph.at(pos)){ if(dist.at(to) > nowd+w){ if(to == start && nowd+w < 0){ route.push_back({epos}); start2 = pos; break; } else if(dist.at(to) > nowd+w && already.at(to) == false){ dist.at(to) = nowd+w; Q.push({dist.at(to),to}); back.at(to) = {pos,epos}; } } } if(route.size()) break; } assert(route.size()); while(start2 != start){ route.push_back(back.at(start2).second); start2 = back.at(start2).first; } reverse(route.begin(),route.end()); cout << route.size() << endl; cout << start+1 << endl; for(long long i=0; i