답안 #1000505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000505 2024-06-17T15:59:18 Z Mardonbekhazratov 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
1000 ms 1080 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;

using namespace std;

vector<int>sub1(int n){
    vector<int>ans;
    for(int i=0;i<n;i++) ans.push_back(i);
    return ans;
}

int n;
vector<vector<int>>v;
vector<int>dp,a,vis;

void dfs(int x){
    int s=x;
    vis[x]=1;
    for(int z:v[x]){
        if(vis[z]!=1){
            if(vis[z]==0) dfs(z);
            if(dp[z]+1>dp[x] && dp[z]>0) s=z,dp[x]=dp[z]+1;
        }
    }
    vis[x]=2;
    a[x]=s;
}

vector<int>f(int x,int y){
    dp.assign(n,0);
    a.resize(n);
    vis.assign(n,0);
    dp[y]=1;
    dfs(x);
    vector<int>ans;
    if(dp[x]==0) return ans;
    while(x!=y){
        ans.push_back(x);
        x=a[x];
    }
    ans.push_back(y);
    return ans;
}

vector<int> longest_trip(int N, int D){
    if(D==3) return sub1(N);
    n=N;
    v.assign(N,vector<int>(0));
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(are_connected({i},{j})){
                v[i].push_back(j);
                v[j].push_back(i);
            }
        }
    }
    vector<int>ans;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            vector<int>b=f(i,j);
            if(b.size()>ans.size()) swap(b,ans);
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 2109 ms 1080 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 30 ms 344 KB Output is correct
3 Correct 245 ms 344 KB Output is correct
4 Execution timed out 1514 ms 344 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Correct 213 ms 344 KB Output is correct
4 Execution timed out 1561 ms 600 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Partially correct 231 ms 344 KB Output is partially correct
4 Execution timed out 1494 ms 600 KB Time limit exceeded
5 Halted 0 ms 0 KB -