답안 #849390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849390 2023-09-14T14:48:55 Z vjudge1 Političari (COCI20_politicari) C++17
10 / 70
15 ms 6236 KB
#include<bits/stdc++.h>
#define int long long
#define ll pair<int,int>
using namespace std;

long long a[505][505];
long long danhdau[505][505];
vector<int> elt;
int vt[505][505];
int n,k;

void dfs(int u,int v)
{
    if (danhdau[u][v]==1)
    {
        elt.pop_back();
        int l=vt[u][v];
        int r=elt.size()-1;
        int leng=r-l+1;
        k-=l;
        k%=leng;
        cout << elt[k+l] << '\n';
        return;
    }
    else
    {
        danhdau[u][v]=1;
        elt.push_back(u);
        vt[u][v]=elt.size()-1;
        if (vt[u][v]==k)
        {
            cout << u;
            return;
        }
        dfs(v,a[v][u]);
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> k;
    k--;
    for (int i=1;i<=n;i++)
    {
        for (int i2=1;i2<=n;i2++)
        {
            cin >> a[i][i2];
        }
    }
    // elt.push_back(1);
    // vt[1][2]=0;
    // danhdau[1]++;
    dfs(1,2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 3 ms 5208 KB Output isn't correct
3 Incorrect 8 ms 5720 KB Output isn't correct
4 Incorrect 10 ms 5980 KB Output isn't correct
5 Incorrect 13 ms 6236 KB Output isn't correct
6 Incorrect 15 ms 6236 KB Output isn't correct
7 Correct 1 ms 4440 KB Output is correct
8 Incorrect 2 ms 4700 KB Output isn't correct
9 Incorrect 4 ms 5212 KB Output isn't correct
10 Incorrect 11 ms 6008 KB Output isn't correct
11 Incorrect 13 ms 6236 KB Output isn't correct
12 Incorrect 13 ms 6236 KB Output isn't correct
13 Incorrect 1 ms 4444 KB Output isn't correct
14 Incorrect 2 ms 4956 KB Output isn't correct