package Yukicoder /** * Created by hichikawa on 2015/11/12. */ fun main(args: Array) { fun readLineLongArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toLong() } return ret } fun readLineLong(): Long { val str = readLine() as String return str.toLong() } fun readLineInt(): Int { val str = readLine() as String return str.toInt() } fun readLineIntArray() : List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toInt() } return ret } fun repaintArray(arrArea : Array>, x : Int, y : Int, color : Int, H : Int, W : Int) : Array>{ if (arrArea[x][y] == color) { return arrArea } arrArea[x][y] = color if (x > 0 && arrArea[x-1][y] != color) { repaintArray(arrArea, x-1, y, color, H, W) } if (y > 0 && arrArea[x][y-1] != color) { repaintArray(arrArea, x, y-1, color, H, W) } if (x < H-1 && arrArea[x+1][y] != color) { repaintArray(arrArea, x+1, y, color, H, W) } if (y < W-1 && arrArea[x][y+1] != color) { repaintArray(arrArea, x, y+1, color, H, W) } return arrArea } val input1 = readLineIntArray() val H = input1[0] val W = input1[1] var arrArea = Array(H , {readLineIntArray().toTypedArray()}) val repaintNum = readLineInt() for (i in 1..repaintNum) { val input = readLineIntArray() repaintArray(arrArea, input[0]-1, input[1]-1, input[2], H, W) } for (line in arrArea) { for ((i, c) in line.withIndex()) { if (i!=0) { print(" ") } print(c) } println() } }