#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define ull unsigned ll
using namespace std;
bool branches[501][501]={};
bool chaychua[501][501][2]={};
long parents[401];
long N,K;
long dp[501][501][2]={};
vector<long> dp1 [501][501][2] = {};
long depth = -1;
long pre(long p){
if (p == 1) return N;
return p-1;
}
long nex(long p){
if (p == N) return 0;
return p+1;
}
long memo(long start, long end,long direction){
if (chaychua[start][end][direction]) return dp[start][end][direction];
chaychua[start][end][direction] = 1;
//counter-clockwise;
if (direction == 0){
for(long i = nex(start);i != end; i = nex(i)){
if (branches[start][i]){
dp[start][end][0] = max(memo(i,end,0),memo(start,i,1))+1;
}
}
}
else{
for(long i = nex(start);i != end;i = nex(i)){
if (branches[end][i]){
dp[start][end][1] = max(memo(i,end,0),memo(start,i,1))+1;
}
}
}
return dp[start][end][direction];
}
int main(){
cin>>N>>K;
long v,u=0;
for(long i = 1;i<=N;i++){
cin>>v;
while(v!=0){
branches[i][v]=1;
cin>>v;
}
}
long maxi = -1;
long mem = 0;
for(long i = 1;i<=N;i++){
//counter-clockwise
long val = memo(i,i,0);
if(val>maxi){
maxi = val;
mem = i;
}
}
cout<<maxi<<endl<<mem<<endl;
}
Compilation message
race.cpp: In function 'int main()':
race.cpp:53:12: warning: unused variable 'u' [-Wunused-variable]
53 | long v,u=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12116 KB |
Output is correct |
2 |
Incorrect |
7 ms |
12116 KB |
Output isn't correct |
3 |
Incorrect |
7 ms |
12244 KB |
Output isn't correct |
4 |
Incorrect |
7 ms |
12244 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
12372 KB |
Output isn't correct |
6 |
Incorrect |
8 ms |
12348 KB |
Output isn't correct |
7 |
Incorrect |
10 ms |
12500 KB |
Output isn't correct |
8 |
Incorrect |
8 ms |
12608 KB |
Output isn't correct |
9 |
Incorrect |
11 ms |
12612 KB |
Output isn't correct |
10 |
Correct |
14 ms |
12756 KB |
Output is correct |
11 |
Incorrect |
15 ms |
12756 KB |
Output isn't correct |
12 |
Incorrect |
33 ms |
13772 KB |
Output isn't correct |
13 |
Incorrect |
68 ms |
14792 KB |
Output isn't correct |
14 |
Incorrect |
98 ms |
15860 KB |
Output isn't correct |
15 |
Incorrect |
292 ms |
16804 KB |
Output isn't correct |
16 |
Incorrect |
369 ms |
16784 KB |
Output isn't correct |
17 |
Incorrect |
290 ms |
16804 KB |
Output isn't correct |
18 |
Incorrect |
167 ms |
16732 KB |
Output isn't correct |
19 |
Incorrect |
388 ms |
16956 KB |
Output isn't correct |
20 |
Incorrect |
449 ms |
16908 KB |
Output isn't correct |