#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int long long
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int a[510][510];
map<pair<int,int>,int>vis;
main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
vector<pair<int,int>>v;
v.pb({0,1});
v.pb({1,2});
vis[{0,1}]=1;
vis[{1,2}]=1;
pair<int,int>ans;
while(1){
int x=v.size()-1;
if(vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]==1){
ans.F=v[x].S;
ans.S=a[v[x].S-1][v[x].F-1];
break;
}
vis[{v[x].S,a[v[x].S-1][v[x].F-1]}]=1;
v.pb({v[x].S,a[v[x].S-1][v[x].F-1]});
}
reverse(v.begin(),v.end());
pair<int,int> lst={-1,-1};
while(((*v.rbegin()).F!=ans.F||(*v.rbegin()).S!=ans.S)&&m>0){
lst=*v.rbegin();
v.pop_back(),m--;
}
if(m==0){
cout<<lst.F<<" "<<lst.S<<endl;
return 0;
}
reverse(v.begin(),v.end());
int xx;
if(m>=v.size()){
m%v.size();
if(xx==0)
xx=v.size();
xx--;
}
xx--;
cout<<v[xx].S<<endl;
return 0;
}
Compilation message
politicari.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main()
| ^~~~
politicari.cpp: In function 'int main()':
politicari.cpp:61:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | if(m>=v.size()){
| ~^~~~~~~~~~
politicari.cpp:63:10: warning: value computed is not used [-Wunused-value]
63 | m%v.size();
| ~^~~~~~~~~
politicari.cpp:64:9: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | if(xx==0)
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
1108 KB |
Output isn't correct |
3 |
Incorrect |
33 ms |
1896 KB |
Output isn't correct |
4 |
Incorrect |
41 ms |
2008 KB |
Output isn't correct |
5 |
Incorrect |
56 ms |
2308 KB |
Output isn't correct |
6 |
Incorrect |
50 ms |
2228 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
724 KB |
Output isn't correct |
9 |
Incorrect |
12 ms |
1236 KB |
Output isn't correct |
10 |
Incorrect |
39 ms |
2072 KB |
Output isn't correct |
11 |
Incorrect |
49 ms |
2228 KB |
Output isn't correct |
12 |
Incorrect |
45 ms |
2260 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
852 KB |
Output isn't correct |