#P6867. [COCI 2019/2020 #5] Politicari

[COCI 2019/2020 #5] Politicari

Description

There are nn people who criticize each other.

You are also given a matrix AA.

The rules are as follows:

  • For the first time, person 11 criticizes person 22.

  • If at the (i1)(i-1)-th time, person uu criticizes person vv,

    then at the ii-th time, person vv criticizes person Av,uA_{v,u}.

Find who is doing the criticizing at the kk-th time (note: not the person being criticized).

Input Format

The first line contains two positive integers, nn and kk.

The next nn lines contain the matrix AA. The main diagonal of the matrix (the diagonal from top-left to bottom-right) is all 00, and all other entries are positive integers from 11 to nn.

Output Format

Output one line containing your answer.

2 4
0 2
1 0

2
3 7
0 3 2
3 0 3
2 1 0

1
4 7
0 4 3 2
4 0 4 1
2 1 0 1
3 2 3 0

3

Hint

Constraints

  • For 3535 pts of the testdata, it is guaranteed that 1k1051 \leq k \leq 10^5.
  • For all testdata, 2n5002 \leq n \leq 500 and 1k10181 \leq k \leq 10^{18}.

Notes

This problem is translated from COCI2019-2020 CONTEST #5 T2 Političari, translated by 90693

Translated by ChatGPT 5