답안 #1049216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049216 2024-08-08T15:04:29 Z Zicrus 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
763 ms 1600 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
 
typedef long long ll;
 
vector<vector<ll>> adj;
vector<bool> vst;
mt19937 mt;
ll sz;

vector<int> mxRand(ll start) {
    ll n = adj.size();
    ll cur = start;
    vector<int> res = {(int)start};
loop:
    vst[cur] = true;
    shuffle(adj[cur].begin(), adj[cur].end(), mt);
    for (auto &e : adj[cur]) {
        if (!vst[e]) {
            cur = e;
            res.push_back(e);
            goto loop;
        }
    }
    for (auto &e : res) vst[e] = false;
    return res;
}

void dfs(ll cur) {
    vst[cur] = true;
    sz++;
    for (auto &e : adj[cur]) {
        if (vst[e]) continue;
        dfs(e);
    }
}
 
vector<int> longest_trip(int n, int d) {
    mt = mt19937(time(0));
    adj = vector<vector<ll>>(n);
    vst = vector<bool>(n);
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (are_connected({i}, {j})) {
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
        }
    }

    sz = 0;
    vst = vector<bool>(n);
    dfs(0);
    bool comp0 = sz > n/2;

    ll start = 0;
    for (int i = 0; i < n; i++) {
        if (comp0 != vst[i]) continue;
        start = i;
        break;
    }
    for (int i = 0; i < n; i++) {
        if (comp0 != vst[i]) continue;
        if (adj[i].size() == 1) start = i;
    }
    
    vst = vector<bool>(n);
    vector<int> res;
    for (int i = 0; i < 10; i++) {
        vector<int> nw = mxRand(start);
        if (nw.size() > res.size()) res = nw;
    }
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> mxRand(ll)':
longesttrip.cpp:13:8: warning: unused variable 'n' [-Wunused-variable]
   13 |     ll n = adj.size();
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 159 ms 912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 120 ms 480 KB Output is correct
4 Correct 359 ms 604 KB Output is correct
5 Correct 700 ms 1072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 116 ms 344 KB Output is correct
4 Correct 368 ms 800 KB Output is correct
5 Correct 725 ms 1220 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 128 ms 476 KB Output is correct
9 Correct 290 ms 600 KB Output is correct
10 Correct 739 ms 1260 KB Output is correct
11 Correct 685 ms 1268 KB Output is correct
12 Correct 663 ms 1128 KB Output is correct
13 Correct 656 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 114 ms 596 KB Output is correct
4 Correct 360 ms 584 KB Output is correct
5 Correct 704 ms 1584 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 110 ms 344 KB Output is correct
9 Correct 248 ms 804 KB Output is correct
10 Correct 687 ms 1244 KB Output is correct
11 Correct 714 ms 1260 KB Output is correct
12 Correct 700 ms 1272 KB Output is correct
13 Correct 686 ms 1360 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 32 ms 340 KB Output is correct
17 Correct 73 ms 344 KB Output is correct
18 Correct 137 ms 344 KB Output is correct
19 Correct 253 ms 776 KB Output is correct
20 Correct 262 ms 344 KB Output is correct
21 Correct 763 ms 1296 KB Output is correct
22 Correct 724 ms 1300 KB Output is correct
23 Correct 740 ms 1600 KB Output is correct
24 Correct 684 ms 1140 KB Output is correct
25 Correct 12 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 18 ms 344 KB Output is correct
28 Correct 20 ms 344 KB Output is correct
29 Correct 17 ms 344 KB Output is correct
30 Correct 180 ms 480 KB Output is correct
31 Correct 171 ms 728 KB Output is correct
32 Correct 156 ms 692 KB Output is correct
33 Correct 283 ms 344 KB Output is correct
34 Correct 285 ms 864 KB Output is correct
35 Correct 269 ms 548 KB Output is correct
36 Correct 718 ms 1060 KB Output is correct
37 Correct 718 ms 1328 KB Output is correct
38 Correct 745 ms 1176 KB Output is correct
39 Correct 686 ms 1140 KB Output is correct
40 Correct 702 ms 1312 KB Output is correct
41 Correct 734 ms 888 KB Output is correct
42 Correct 724 ms 720 KB Output is correct
43 Correct 699 ms 1140 KB Output is correct
44 Correct 743 ms 872 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 11 ms 344 KB Output is correct
47 Correct 19 ms 344 KB Output is correct
48 Correct 16 ms 344 KB Output is correct
49 Correct 18 ms 344 KB Output is correct
50 Correct 164 ms 488 KB Output is correct
51 Correct 159 ms 592 KB Output is correct
52 Correct 159 ms 464 KB Output is correct
53 Correct 277 ms 544 KB Output is correct
54 Correct 265 ms 684 KB Output is correct
55 Correct 253 ms 540 KB Output is correct
56 Correct 761 ms 1252 KB Output is correct
57 Correct 747 ms 1216 KB Output is correct
58 Correct 705 ms 948 KB Output is correct
59 Incorrect 738 ms 1172 KB Incorrect
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 23 ms 340 KB Output is correct
3 Partially correct 114 ms 344 KB Output is partially correct
4 Partially correct 360 ms 748 KB Output is partially correct
5 Partially correct 746 ms 1232 KB Output is partially correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Partially correct 119 ms 484 KB Output is partially correct
9 Partially correct 253 ms 804 KB Output is partially correct
10 Partially correct 731 ms 1508 KB Output is partially correct
11 Partially correct 710 ms 1316 KB Output is partially correct
12 Partially correct 732 ms 1276 KB Output is partially correct
13 Partially correct 729 ms 1344 KB Output is partially correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 33 ms 344 KB Output is correct
17 Partially correct 72 ms 344 KB Output is partially correct
18 Partially correct 130 ms 592 KB Output is partially correct
19 Partially correct 269 ms 828 KB Output is partially correct
20 Partially correct 265 ms 344 KB Output is partially correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 19 ms 344 KB Output is correct
24 Correct 20 ms 344 KB Output is correct
25 Correct 18 ms 344 KB Output is correct
26 Partially correct 192 ms 724 KB Output is partially correct
27 Partially correct 155 ms 720 KB Output is partially correct
28 Partially correct 157 ms 448 KB Output is partially correct
29 Partially correct 264 ms 612 KB Output is partially correct
30 Partially correct 260 ms 548 KB Output is partially correct
31 Partially correct 241 ms 592 KB Output is partially correct
32 Correct 8 ms 344 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 18 ms 344 KB Output is correct
35 Correct 17 ms 344 KB Output is correct
36 Correct 27 ms 344 KB Output is correct
37 Partially correct 181 ms 596 KB Output is partially correct
38 Incorrect 8 ms 344 KB Incorrect
39 Halted 0 ms 0 KB -