namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { object? Solve() { var n = Int(); var m = Int(); var adjz = n.Repeat(() => new Dictionary()); for (var i = 0; i < m; i++) { var u = Int() - 1; var v = Int() - 1; var w = Int(); if (adjz[u].TryGetValue(v, out var p)) { var (pw, pj) = p; if (pw == w) continue; Out(2); if (w > pw) { Out(v + 1); } else { Out(u + 1); } Out(pj + " " + (i + 1)); return null; } adjz[u][v] = (w, i + 1); adjz[v][u] = (-w, i + 1); } var dz = new long[n]; var last = n.Repeat(() => -1); var lj = n.Repeat(() => -1); var ans = new List(); void S(int v, int prev) { if (ans.Count > 0) return; foreach (var (next, value) in adjz[v]) { var (w, j) = value; if (j == prev) continue; var nd = dz[v] + w; if (last[next] != -1) { if (dz[next] != nd && ans.Count == 0) { var k = v; ans.Add(j); while (k != next && k >= 0) { ans.Add(lj[k]); k = last[k]; } if (dz[next] < nd) ans.Reverse(); Out(ans.Count); Out(next + 1); Out(ans, " "); return; } continue; } dz[next] = nd; last[next] = v; lj[next] = j; S(next, j); } } for (var start = 0; start < n; start++) { if (last[start] != -1) continue; dz[start] = 0; last[start] = -2; S(start, -1); } if (ans.Count == 0) return -1; return null; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Trim().Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } }