# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
544169 | AlperenT | Političari (COCI20_politicari) | C++17 | 18 ms | 4300 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 5;
long long n, k, graph[N][N], dist[N][N];
struct Item{
long long a, b;
};
Item cur = {1, 2};
bool flag;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> k;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> graph[i][j];
}
}
if(k == 1) cout << 1;
else{
dist[1][2] = 2, k -= 2;
while(k > 0){
k--;
if(flag) cur = {cur.b, graph[cur.b][cur.a]};
else{
if(dist[cur.b][graph[cur.b][cur.a]] == 0){
dist[cur.b][graph[cur.b][cur.a]] = dist[cur.a][cur.b] + 1;
cur = {cur.b, graph[cur.b][cur.a]};
}
else{
k %= dist[cur.a][cur.b] - dist[cur.b][graph[cur.b][cur.a]] + 1;
cur = {cur.b, graph[cur.b][cur.a]};
flag = true;
}
}
}
}
cout << cur.b;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |