Submission #1049217

# Submission time Handle Problem Language Result Execution time Memory
1049217 2024-08-08T15:06:54 Z Zicrus Longest Trip (IOI23_longesttrip) C++17
5 / 100
732 ms 2208 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 < 1; 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();
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 174 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 107 ms 484 KB Output is correct
4 Correct 295 ms 784 KB Output is correct
5 Correct 714 ms 1168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 17 ms 344 KB Output is correct
3 Correct 112 ms 344 KB Output is correct
4 Correct 305 ms 804 KB Output is correct
5 Correct 718 ms 1112 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Incorrect 1 ms 344 KB Incorrect
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 121 ms 344 KB Output is correct
4 Correct 362 ms 592 KB Output is correct
5 Correct 698 ms 1500 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 127 ms 592 KB Output is correct
9 Correct 272 ms 848 KB Output is correct
10 Correct 703 ms 1204 KB Output is correct
11 Correct 670 ms 1252 KB Output is correct
12 Correct 727 ms 1268 KB Output is correct
13 Correct 685 ms 1516 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 42 ms 344 KB Output is correct
17 Correct 74 ms 344 KB Output is correct
18 Correct 119 ms 588 KB Output is correct
19 Correct 257 ms 772 KB Output is correct
20 Correct 244 ms 672 KB Output is correct
21 Correct 713 ms 1844 KB Output is correct
22 Correct 696 ms 1172 KB Output is correct
23 Correct 732 ms 1400 KB Output is correct
24 Correct 684 ms 2208 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 18 ms 344 KB Output is correct
28 Correct 19 ms 344 KB Output is correct
29 Correct 17 ms 344 KB Output is correct
30 Correct 166 ms 724 KB Output is correct
31 Correct 164 ms 464 KB Output is correct
32 Correct 167 ms 600 KB Output is correct
33 Correct 236 ms 780 KB Output is correct
34 Correct 241 ms 556 KB Output is correct
35 Correct 270 ms 548 KB Output is correct
36 Correct 670 ms 1004 KB Output is correct
37 Correct 621 ms 1224 KB Output is correct
38 Correct 637 ms 1264 KB Output is correct
39 Correct 587 ms 1328 KB Output is correct
40 Correct 596 ms 940 KB Output is correct
41 Correct 715 ms 928 KB Output is correct
42 Correct 716 ms 856 KB Output is correct
43 Correct 665 ms 1080 KB Output is correct
44 Correct 624 ms 1048 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 24 ms 344 KB Output is correct
48 Correct 24 ms 344 KB Output is correct
49 Correct 23 ms 444 KB Output is correct
50 Correct 136 ms 476 KB Output is correct
51 Incorrect 39 ms 472 KB Incorrect
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Partially correct 115 ms 600 KB Output is partially correct
4 Partially correct 300 ms 576 KB Output is partially correct
5 Partially correct 626 ms 996 KB Output is partially correct
6 Correct 5 ms 344 KB Output is correct
7 Incorrect 2 ms 344 KB Incorrect
8 Halted 0 ms 0 KB -