fork download
  1. package TRGAME
  2.  
  3. import kotlin.system.exitProcess
  4.  
  5. fun main(args: Array<String>) {
  6. if(args.isNotEmpty()) {
  7. System.setIn(java.io.FileInputStream(args[0]))
  8. }
  9. if(args.size >= 2) {
  10. System.setOut(java.io.PrintStream(args[1]))
  11. }
  12.  
  13. val numTests = readLine()!!.toInt()
  14. require(numTests in 1..100000)
  15.  
  16. var sumN = 0
  17.  
  18. repeat(numTests) {
  19. val N = readLine()!!.toInt()
  20. require(N in 1..100000)
  21.  
  22. sumN += N
  23. require(sumN <= 100000)
  24.  
  25. val gph = List(N) { mutableListOf<Int>() }
  26. run {
  27. val grp = IntArray(N) { it }
  28. fun get_group(u: Int): Int {
  29. if(grp[u] != u) {
  30. grp[u] = get_group(grp[u])
  31. }
  32. return grp[u]
  33. }
  34.  
  35. repeat(N-1) {
  36. val (u, v) = readLine()!!.split(" ").map{ it.toInt() - 1 }
  37. require(u in 0 until N)
  38. require(v in 0 until N)
  39.  
  40. gph[u].add(v)
  41. gph[v].add(u)
  42.  
  43. val a = get_group(u)
  44. val b = get_group(v)
  45. require(a != b)
  46. grp[a] = b
  47. }
  48. }
  49.  
  50. val subtreeSize = IntArray(N)
  51.  
  52. run {
  53. val visited = BooleanArray(N)
  54. val queue: java.util.Queue<Int> = java.util.ArrayDeque<Int>()
  55. val order = mutableListOf<Int>()
  56. queue.add(0)
  57. visited[0] = true
  58. while(!queue.isEmpty()) {
  59. val u = queue.poll()
  60. order.add(u)
  61. for(v in gph[u]) if(!visited[v]) {
  62. queue.add(v)
  63. visited[v] = true
  64. }
  65. }
  66.  
  67. order.reverse()
  68. for(u in order) {
  69. subtreeSize[u] = gph[u].map{ subtreeSize[it] }.sum() + 1
  70. }
  71. }
  72.  
  73. if(N % 2 == 0) {
  74. println(List(N) { x -> if(maxOf(gph[x].map{ subtreeSize[it] }.filter{ it < subtreeSize[x] }.max()?:0, N - subtreeSize[x]) * 2 <= N) 1 else 0 }.joinToString(""))
  75. }else {
  76. println("0".repeat(N))
  77. }
  78. }
  79.  
  80. require(readLine() == null)
  81. }
Runtime error #stdin #stdout #stderr 0.09s 34016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" kotlin.KotlinNullPointerException
	at TRGAME.ProgKt.main(prog.kt:13)