import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val m = n val adj = Array(n) { mutableListOf() } val edges = mutableMapOf, Stack>() for (i in 0 until m) { val v1 = nextInt() - 1 val v2 = nextInt() - 1 adj[v1].add(v2) adj[v2].add(v1) val pair = min(v1, v2) to max(v1, v2) if (!edges.containsKey(pair)) { edges[pair] = Stack() } edges[pair]?.push(i) } val choice = Array(n) { -1 } val visited = BooleanArray(n) { false } val chosen = BooleanArray(n) { false } for (i in 0 until n) { if (visited[i]) continue val stack = Stack>() stack.push(i to -1) while (stack.isNotEmpty()) { val (v, p) = stack.pop() for (w in adj[v]) { if (w != p && w != v) { stack.push(w to v) } val min = min(v, w) val max = max(v, w) if (edges[min to max]?.isNotEmpty()!!) { val num = edges[min to max]?.pop()!! if (!chosen[min]) { chosen[min] = true choice[num] = min } else { chosen[max] = true choice[num] = max } } } } } if (chosen.any { !it }) { println("No") } else { println("Yes") println(choice.map { it + 1 }.joinToString("\n")) } } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion