Submission #849376

# Submission time Handle Problem Language Result Execution time Memory
849376 2023-09-14T14:28:18 Z vjudge1 Političari (COCI20_politicari) C++17
10 / 70
16 ms 8416 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];
vector<int> elt;
int vt[505];
int n,k;

void dfs(int u,int v)
{
    if (danhdau[v]>n)
    {
        int l=vt[v];
        int r=vt[u];
        int leng=r-l+1;
        k-=l;
        k%=leng;
        cout << elt[k+l] << '\n';
        return;
    }
    else
    {
        danhdau[v]++;
        elt.push_back(v);
        if (vt[v]==0) vt[v]=elt.size()-1;
        if (vt[v]==k)
        {
            cout << v;
            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]=0;
    danhdau[1]++;
    dfs(1,2);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 5 ms 1628 KB Output isn't correct
3 Incorrect 9 ms 3116 KB Output isn't correct
4 Incorrect 10 ms 3052 KB Output isn't correct
5 Runtime error 16 ms 8416 KB Execution killed with signal 8
6 Incorrect 13 ms 3808 KB Output isn't correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 1116 KB Output isn't correct
9 Incorrect 4 ms 2136 KB Output isn't correct
10 Incorrect 13 ms 3296 KB Output isn't correct
11 Incorrect 15 ms 4320 KB Output isn't correct
12 Incorrect 13 ms 3420 KB Output isn't correct
13 Incorrect 1 ms 604 KB Output isn't correct
14 Incorrect 2 ms 1112 KB Output isn't correct