제출 #1019223

#제출 시각아이디문제언어결과실행 시간메모리
1019223LIF가장 긴 여행 (IOI23_longesttrip)C++17
40 / 100
948 ms2568 KiB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
bool vis[5005];
int dep[5005];
int pre[5005];
bool in_queue[5005];
vector<int> edge[50005];
void dfs(int now)
{
    vis[now] = true;
    for(auto it : edge[now])
    {
        if(vis[it] == true)continue;
        dep[it] = dep[now] + 1;
        pre[it] = now;
        dfs(it);
    }
}
vector<int> longest_trip(int N, int D)
{
    for(int i=0;i<N;i++)edge[i].clear();
    for(int i=1;i<N;i++)
    {
        for(int j=0;j<i;j++)
        {
            vector<int> A;
            vector<int> B;
            A.push_back(i);
            B.push_back(j);
            if(are_connected(A,B) == true)
            {
                edge[i].push_back(j);
                edge[j].push_back(i);
            }
        }
    }
    vector<int> ans;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)pre[j] = -1;
        for(int j=0;j<N;j++)dep[j] = 0;
        for(int j=0;j<N;j++)vis[j] = false;
        dfs(i);
        int maxid = 0;
        int maxn = -1;
        for(int j=0;j<N;j++)
        {
            if(dep[j] > maxn)
            {
                maxn = dep[j];
                maxid = j;
            }
        }
        vector<int> v;
        while(maxid != -1)
        {
            v.push_back(maxid);
            maxid = pre[maxid];
        }
        if(v.size() >= ans.size())
        {
            ans = v;
        }
    }
    return ans;
    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...