#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector>> Graph(N); for(int i=0; i> u >> v; u--; v--; int 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}); int 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;} bool end = false; vector route; already.assign(M,false); auto dfs = [&](auto dfs,int pos,long long nowd) -> void { if(route.size() && pos == start){ if(nowd >= 0) return; end = true; cout << route.size() << endl; cout << start+1 << endl; for(int i=0; i