# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
229234 | VEGAnn | Političari (COCI20_politicari) | C++14 | 28 ms | 3968 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
const int N = 510;
vector<pii> vc, cyc;
ll k;
int n, nt[N][N], mrk[N][N], tim[N][N], tt = 0;
void CYCLE(pii lst){
cyc.clear();
vc.PB(MP(-1, -1));
do {
vc.pop_back();
cyc.PB(vc.back());
} while (vc.back() != lst);
reverse(all(cyc));
k -= ll(tim[lst.ft][lst.sd]);
k %= sz(cyc);
cout << cyc[k].ft + 1;
exit(0);
}
void dfs(int x, int y){
tt++;
tim[x][y] = tt;
if (ll(tt) == k){
cout << x + 1;
exit(0);
}
vc.PB(MP(x, y));
mrk[x][y] = 1;
int nw = nt[x][y];
if (mrk[nw][x] == 0)
dfs(nw, x); else
if (mrk[nw][x] == 1)
CYCLE(MP(nw, x));
mrk[x][y] = 2;
vc.pop_back();
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n >> k;
if (k == 1){
cout << 1;
return 0;
}
k--;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++){
cin >> nt[i][j];
nt[i][j]--;
}
dfs(1, 0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |