#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); set s; for(int i = 0;i>u>>v>>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< 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; int cnt = ans.size(); que.clear(); for(int i = 0;i