제출 #713647

#제출 시각아이디문제언어결과실행 시간메모리
713647aedmhsn연결리스트 수사하기 (NOI12_forensic)C++17
5 / 25
1083 ms340 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a)) 
 
#define boost() ios_base::sync_with_stdio(false); cin.tie(0)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
 
const int mxN=2e4+5;

vector <int> a(mxN);


 
int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i];
    int ans1=0;
    for(int i=0; i<n; i++){
        int before=a[i];
        for(int j=-1; j<n; j++){
            a[i]=j;
            bool path1[mxN]={};
            int lnode=0, ans=0;
            while(lnode != -1 && !path1[lnode]){
                path1[lnode]=1;
                ans++;
                lnode = a[lnode];
            }
            if(lnode == -1)
                ans1 = max(ans, ans1);
        }
        a[i] = before;
    }
    cout << ans1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...