#include<bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
int n,k;
int way[maxn][maxn];
int dp[maxn][maxn][2];
int f(int u, int v, int t) {
if(dp[u][v][t]==-1) {
dp[u][v][t] = 0;
int wow = (t==0 ? 1:-1);
for(int x=(u+wow+n)%n;x!=v;x=(x+wow+n)%n) {
if(!way[u][x]) continue;
dp[u][v][t] = max(dp[u][v][t], max(f(x,u,!t), f(x,v,t)) + 1);
}
}
return dp[u][v][t];
}
int main() {
scanf("%d%d",&n,&k);
for(int u=0;u<n;u++) {
int v;
while(scanf("%d",&v) && v) way[u][v-1] = 1;
}
memset(dp,-1,sizeof(dp));
pair<int,int> res = {-1,-1};
for(int u=0;u<n;u++) res = max(res, {f(u,u,0), u});
printf("%d\n%d",res.first,res.second);
}
Compilation message
race.cpp: In function 'int main()':
race.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2300 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2416 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
2596 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
2596 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
2596 KB |
Output isn't correct |
6 |
Incorrect |
9 ms |
2596 KB |
Output isn't correct |
7 |
Correct |
11 ms |
2836 KB |
Output is correct |
8 |
Incorrect |
11 ms |
2836 KB |
Output isn't correct |
9 |
Incorrect |
21 ms |
2836 KB |
Output isn't correct |
10 |
Correct |
22 ms |
2836 KB |
Output is correct |
11 |
Incorrect |
26 ms |
2896 KB |
Output isn't correct |
12 |
Incorrect |
122 ms |
3136 KB |
Output isn't correct |
13 |
Incorrect |
336 ms |
3336 KB |
Output isn't correct |
14 |
Incorrect |
725 ms |
3616 KB |
Output isn't correct |
15 |
Incorrect |
1951 ms |
4044 KB |
Output isn't correct |
16 |
Incorrect |
2223 ms |
4088 KB |
Output isn't correct |
17 |
Incorrect |
1954 ms |
4232 KB |
Output isn't correct |
18 |
Incorrect |
1232 ms |
4268 KB |
Output isn't correct |
19 |
Incorrect |
2298 ms |
4504 KB |
Output isn't correct |
20 |
Incorrect |
2239 ms |
4672 KB |
Output isn't correct |