답안 #1073258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073258 2024-08-24T11:19:37 Z Unforgettablepl 가장 긴 여행 (IOI23_longesttrip) C++17
25 / 100
909 ms 1404 KB
#pragma GCC optimize("Ofast","unroll-all-loops")
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> longest_trip(int N,int D){
    vector<vector<int>> adj(N);
    for(int i=0;i<N;i++) {
        for(int j=i+1;j<N;j++) {
            if(are_connected({i},{j})) {
                adj[i].emplace_back(j);
                adj[j].emplace_back(i);
            }
        }
    }
    int ans = 0;
    int lim = N/2 + (N&1);
    for(int i=0;i<N;i++) {
        vector<bool> visited(N);
        function<void(int,int)> dfs = [&](int x,int depth) {
            visited[x]=true;
            ans=max(ans,depth);
            for(int&v:adj[x])if(!visited[v])dfs(v,depth+1);
        };
        dfs(i,0);
        if(ans>=lim)break;
    }
    vector<int> full;
    ans = min(ans,lim);
    for(int i=0;i<N;i++) {
        stack<int> path;
        vector<bool> visited(N);
        function<void(int,int)> dfs = [&](int x,int depth) {
            visited[x]=true;
            path.emplace(x);
            if(ans==depth) {
                while(!path.empty()) {
                    full.emplace_back(path.top());
                    path.pop();
                }
            }
            for(int&v:adj[x])if(!visited[v]) {
                dfs(v,depth+1);
                if(!full.empty())return;
            }
            path.pop();
        };
        dfs(i,0);
        if(!full.empty())return full;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:7:30: warning: control reaches end of non-void function [-Wreturn-type]
    7 |     vector<vector<int>> adj(N);
      |                              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 137 ms 460 KB Output is correct
4 Correct 446 ms 748 KB Output is correct
5 Correct 839 ms 1272 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Correct 156 ms 344 KB Output is correct
9 Correct 349 ms 492 KB Output is correct
10 Correct 859 ms 1112 KB Output is correct
11 Correct 851 ms 852 KB Output is correct
12 Correct 828 ms 980 KB Output is correct
13 Correct 862 ms 1024 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 38 ms 344 KB Output is correct
17 Correct 77 ms 344 KB Output is correct
18 Correct 160 ms 436 KB Output is correct
19 Correct 334 ms 744 KB Output is correct
20 Correct 331 ms 660 KB Output is correct
21 Correct 907 ms 1000 KB Output is correct
22 Correct 825 ms 912 KB Output is correct
23 Correct 826 ms 1404 KB Output is correct
24 Correct 805 ms 1032 KB Output is correct
25 Correct 7 ms 596 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 22 ms 344 KB Output is correct
28 Correct 22 ms 344 KB Output is correct
29 Correct 21 ms 344 KB Output is correct
30 Correct 168 ms 848 KB Output is correct
31 Correct 216 ms 344 KB Output is correct
32 Correct 204 ms 344 KB Output is correct
33 Correct 310 ms 344 KB Output is correct
34 Correct 314 ms 860 KB Output is correct
35 Correct 309 ms 708 KB Output is correct
36 Correct 872 ms 1256 KB Output is correct
37 Correct 724 ms 744 KB Output is correct
38 Correct 714 ms 996 KB Output is correct
39 Correct 787 ms 932 KB Output is correct
40 Correct 817 ms 972 KB Output is correct
41 Correct 848 ms 1076 KB Output is correct
42 Correct 899 ms 900 KB Output is correct
43 Correct 805 ms 1032 KB Output is correct
44 Correct 854 ms 1284 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 12 ms 344 KB Output is correct
47 Correct 21 ms 344 KB Output is correct
48 Correct 23 ms 344 KB Output is correct
49 Correct 20 ms 344 KB Output is correct
50 Correct 196 ms 344 KB Output is correct
51 Correct 208 ms 600 KB Output is correct
52 Correct 196 ms 340 KB Output is correct
53 Correct 308 ms 732 KB Output is correct
54 Correct 267 ms 728 KB Output is correct
55 Correct 307 ms 592 KB Output is correct
56 Correct 909 ms 944 KB Output is correct
57 Correct 850 ms 924 KB Output is correct
58 Correct 822 ms 904 KB Output is correct
59 Correct 881 ms 1000 KB Output is correct
60 Correct 869 ms 916 KB Output is correct
61 Correct 851 ms 736 KB Output is correct
62 Correct 890 ms 780 KB Output is correct
63 Correct 827 ms 908 KB Output is correct
64 Correct 819 ms 1028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -