#include #include #include using namespace std; using ll = long long; #include int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin>>n>>m; vector>>> g(n); vector C(m); set s; for(int i = 0;i>u>>v>>c; C[i] = c; u--;v--; s.insert(c); g[u].push_back({v,{c,i+1}}); g[v].push_back({u,{c,i+1}}); } if(s.size()==1){ cout<<-1< ans; for(int i = 0;i<3;i++){ set a; set b; vector use; for(int j = 0;j now; for(auto itr:g[i]){ now.insert(itr.second.first); } if(now.size()==1) continue; wu = i; break; } vector vis(n,0); bool fn = false; vector que; auto dfs = [&](auto dfs,int ni,int to) -> void { vis[ni]++; if(ni==to){ fn = true; return; } for(auto&itr:g[ni]){ int nj = itr.first; if(vis[nj]) continue; que.push_back(itr.second.second); dfs(dfs,nj,to); if(fn) return; que.pop_back(); } }; dfs(dfs,0,wu); vector ans = que; que.clear(); int k = wu; if(wu==0){ int ni = 0; int nj; for(int j = 1;j