제출 #1218957

#제출 시각아이디문제언어결과실행 시간메모리
1218957im2xtreme가장 긴 여행 (IOI23_longesttrip)C++20
0 / 100
1085 ms724 KiB
#include <vector>
#include "longesttrip.h"
using namespace std;

vector<vector<int>> adj;
vector<bool> visited;
vector<int> current_path, best_path;

void dfs(int u) {
    visited[u] = true;
    current_path.push_back(u);

    if (current_path.size() > best_path.size()) {
        best_path = current_path;
    }

    for (int v : adj[u]) {
        if (!visited[v]) {
            dfs(v);
        }
    }

    visited[u] = false;
    current_path.pop_back();
}

vector<int> longest_trip(int N, int D) {
    adj = vector<vector<int>>(N);
    visited = vector<bool>(N, false);
    best_path.clear();

    for (int u = 0; u < N; ++u) {
        for (int v = u + 1; v < N; ++v) {
            vector<int> A = {u}, B = {v};
            if (are_connected(A, B)) {
                adj[u].push_back(v);
                adj[v].push_back(u);
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        current_path.clear();
        dfs(i);
    }

    return best_path;
}
#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...