답안 #841552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841552 2023-09-01T16:45:42 Z Stavab 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
27 ms 348 KB
#include "longesttrip.h"
#include <algorithm>

std::vector<std::vector<int>> graph;
std::vector<int> solution, visited, temp;

void dfs(int n, std::vector<int> &v)
{
    if(visited[n]) return;

    visited[n] = 1;
    v.push_back(n);
    for(int i = 0; i < graph[n].size(); i++)
        dfs(graph[n][i], v);

    if(temp.size() > solution.size())
        solution = temp;

    temp.pop_back();
}

std::vector<int> longest_trip(int N, int D)
{
    graph.assign(N, std::vector<int>());
    for(int i = 0; i < N; i++)
    {
        for(int j = i + 1; j < N; j++)
        {
            if(are_connected({i}, {j}));
            {
                graph[i].push_back(j);
                graph[j].push_back(i);
            }
        }
    }

    visited.assign(N, 0);
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
            visited[j] = 0;
        dfs(i, temp);
    }

    return solution;
}

Compilation message

longesttrip.cpp: In function 'void dfs(int, std::vector<int>&)':
longesttrip.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < graph[n].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:29:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   29 |             if(are_connected({i}, {j}));
      |             ^~
longesttrip.cpp:30:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   30 |             {
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Incorrect 24 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 344 KB Output is correct
2 Incorrect 27 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Incorrect 22 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Incorrect 26 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -