제출 #1280917

#제출 시각아이디문제언어결과실행 시간메모리
1280917avighna가장 긴 여행 (IOI23_longesttrip)C++20
5 / 100
349 ms764 KiB
#include <bits/stdc++.h>

bool are_connected(std::vector<int> A, std::vector<int> B);

std::vector<int> longest_trip(int n, int d) {
  std::vector<std::vector<int>> adj(n);
  auto add_edge = [&](int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
  };
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (are_connected({i}, {j})) {
        add_edge(i, j);
      }
    }
  }

  std::deque<int> _ans;
  for (int u = 0; u < n; ++u) {
    std::deque<int> ans;
    ans.push_back(u);
    std::vector<bool> vis(n);
    vis[u] = true;
    bool changed = true;
    while (changed) {
      changed = false;
      for (int &i : adj[ans.front()]) {
        if (vis[i]) {
          continue;
        }
        vis[i] = true;
        ans.push_front(i);
        changed = true;
      }
      for (int &i : adj[ans.back()]) {
        if (vis[i]) {
          continue;
        }
        vis[i] = true;
        ans.push_back(i);
        changed = true;
      }
    }
    if (ans.size() > _ans.size()) {
      _ans=ans;
    }
  }

  return std::vector<int>(_ans.begin(), _ans.end());
}
#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...