Submission #948772

# Submission time Handle Problem Language Result Execution time Memory
948772 2024-03-18T13:49:39 Z thinknoexit Longest Trip (IOI23_longesttrip) C++17
15 / 100
767 ms 1212 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
using ll = long long;
int n, d;
vector<int> adj2[266];
int col[266];
vector<int> r1, r2;
vector<int> t1, t2;
void dfs(int v) {
    if (col[v] == 1) t1.push_back(v);
    else t2.push_back(v);
    for (auto& x : adj2[v]) {
        if (!col[x]) col[x] = 3 - col[v], dfs(x);
    }
}
vector<int> longest_trip(int N, int D) {
    n = N;
    d = D;
    vector<vector<int>> adj(n, vector<int>(n, 1));
    r1.clear(), r2.clear();
    for (int i = 0;i < n;i++) {
        for (int j = i + 1;j < n;j++) {
            adj[i][j] = adj[j][i] = are_connected({ i }, { j });
            if (!adj[i][j]) adj2[i].push_back(j), adj2[j].push_back(i);
        }
    }
    int tot = 0;
    for (int i = 0;i < n;i++) {
        if (!col[i]) {
            col[i] = 1;
            dfs(i);
            if (tot == 0) {
                tot = 1;
            }
            else {
                bool ch = 0;
                for (auto& x : r1) for (auto& y : t2) if (adj[x][y]) ch = 1;
                for (auto& x : r2) for (auto& y : t1) if (adj[x][y]) ch = 1;
                if (ch) {
                    swap(t1, t2);
                    for (auto& x : t1) col[x] = 3 - col[x];
                    for (auto& x : t2) col[x] = 3 - col[x];
                }
            }
            for (auto& x : t1) r1.push_back(x);
            for (auto& x : t2) r2.push_back(x);
            t1.clear(), t2.clear();
        }
    }
    for (int i = 0;i < n;i++) adj2[i].clear(), col[i] = 0;
    if ((int)r1.size() == n) return r1; // Complete Graph
    int s1 = r1.size(), s2 = r2.size();
    for (int i = 0;i < s1;i++) {
        for (int j = 0;j < s2;j++) {
            if (adj[r1[i]][r2[j]]) {
                swap(r1[i], r1[s1 - 1]);
                swap(r2[0], r2[j]);
                vector<int> ans;
                for (auto& x : r1) ans.push_back(x);
                for (auto& x : r2) ans.push_back(x);
                return ans;
            }
        }
    }
    if (r1.size() > r2.size()) return r1;
    return r2;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 175 ms 1212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 105 ms 344 KB Output is correct
4 Correct 338 ms 492 KB Output is correct
5 Correct 714 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 18 ms 344 KB Output is correct
3 Correct 113 ms 344 KB Output is correct
4 Correct 328 ms 488 KB Output is correct
5 Correct 659 ms 600 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 121 ms 596 KB Output is correct
9 Correct 278 ms 464 KB Output is correct
10 Correct 767 ms 692 KB Output is correct
11 Correct 683 ms 688 KB Output is correct
12 Correct 689 ms 692 KB Output is correct
13 Correct 731 ms 696 KB Output is correct
# 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 Correct 123 ms 344 KB Output is correct
4 Correct 355 ms 592 KB Output is correct
5 Correct 754 ms 600 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 127 ms 600 KB Output is correct
9 Correct 279 ms 480 KB Output is correct
10 Correct 718 ms 852 KB Output is correct
11 Correct 716 ms 692 KB Output is correct
12 Correct 686 ms 848 KB Output is correct
13 Correct 731 ms 944 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 15 ms 344 KB Output is correct
16 Incorrect 2 ms 344 KB Incorrect
17 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 112 ms 344 KB Output is partially correct
4 Partially correct 329 ms 484 KB Output is partially correct
5 Partially correct 706 ms 600 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Partially correct 132 ms 600 KB Output is partially correct
9 Partially correct 284 ms 480 KB Output is partially correct
10 Partially correct 720 ms 944 KB Output is partially correct
11 Partially correct 764 ms 688 KB Output is partially correct
12 Partially correct 741 ms 696 KB Output is partially correct
13 Partially correct 723 ms 700 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Incorrect 2 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -