답안 #846707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846707 2023-09-08T09:27:58 Z Trisanu_Das 가장 긴 여행 (IOI23_longesttrip) C++17
컴파일 오류
0 ms 0 KB
#include "longesttrip.h" 
#include <bits/stdc++.h>
using namespace std;
 
vector<int> longest_trip(int N, int D) {
    vector<int> ans = {0};
    bool vis[N];
    vis[0] = true;
    bool adj[N][N];
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) adj[i][j] = adj[j][i] = are_connected({i}, {j});
    while (true) {
        if (ans.size() == N) return ans;
        bool flag = false;
        for (int i = 0; i < N && !flag; i++) {
            if (!vis[i]) {
                if (adj[path[0]][i])) {
                    ans.insert(ans.begin(), i);
                    flag = true;
                    vis[i] = true;
                    break;
                }
                if (adj[ans.back()][i])) {
                    ans.push_back(i);
                    flag = true;
                    vis[i] = true;
                    break;
                }
                for (int j = 0; j < ans.size(); j++) {
                    if (adj[ans[j]][i])) {
                        vector<int> new_path;
                        new_path.insert(new_path.end(), ans.begin() + j + 1, ans.end());
                        new_path.insert(new_path.end(), ans.begin(), ans.begin() + j + 1);
                        ans = new_path;
                        ans.push_back(i);
                        flag = true;
                        vis[i] = true;
                        break;
                    }
                }
            }
        }
        if (!flag) {
            if (ans.size() >= (N - ans.size())) return ans;
            ans.clear()
            for (int i = 0; i < N; ++i) if (!vis[i]) ans.push_back(i);
            return ans;
        }
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:12:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   12 |         if (ans.size() == N) return ans;
      |             ~~~~~~~~~~~^~~~
longesttrip.cpp:16:25: error: 'path' was not declared in this scope; did you mean 'std::filesystem::__cxx11::path'?
   16 |                 if (adj[path[0]][i])) {
      |                         ^~~~
      |                         std::filesystem::__cxx11::path
In file included from /usr/include/c++/10/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/fs_path.h:184:9: note: 'std::filesystem::__cxx11::path' declared here
  184 |   class path
      |         ^~~~
longesttrip.cpp:16:37: error: expected primary-expression before ')' token
   16 |                 if (adj[path[0]][i])) {
      |                                     ^
longesttrip.cpp:22:40: error: expected primary-expression before ')' token
   22 |                 if (adj[ans.back()][i])) {
      |                                        ^
longesttrip.cpp:28:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                 for (int j = 0; j < ans.size(); j++) {
      |                                 ~~^~~~~~~~~~~~
longesttrip.cpp:29:40: error: expected primary-expression before ')' token
   29 |                     if (adj[ans[j]][i])) {
      |                                        ^
longesttrip.cpp:44:24: error: expected ';' before 'for'
   44 |             ans.clear()
      |                        ^
      |                        ;
   45 |             for (int i = 0; i < N; ++i) if (!vis[i]) ans.push_back(i);
      |             ~~~         
longesttrip.cpp:45:29: error: 'i' was not declared in this scope
   45 |             for (int i = 0; i < N; ++i) if (!vis[i]) ans.push_back(i);
      |                             ^