답안 #948748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948748 2024-03-18T13:00:54 Z thinknoexit 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
778 ms 852 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
using ll = long long;
int n, d;
vector<int> longest_trip(int N, int D) {
    n = N;
    d = D;
    vector<vector<int>> adj(n, vector<int>(n, 1));
    vector<int> deg(n, 0), p(n, 0);
    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]) deg[i]++, deg[j]++;
        }
    }
    set<int> rem;
    for (int i = 0;i < n;i++) if (deg[i] != n - 1) rem.insert(i);
    queue<int> q;
    while (!rem.empty()) {
        for (auto& i : rem) {
            q.push(i);
            p[i] = 1;
            rem.erase(i);
            break;
        }
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            vector<int> del;
            for (auto& i : rem) {
                if (!p[i] && !adj[v][i]) {
                    p[i] = 3 - p[v];
                    del.push_back(i);
                    q.push(i);
                }
            }
            for (auto& x : del) rem.erase(x);
        }
    }
    vector<int> r1, r2;
    for (int i = 0;i < n;i++) {
        if (!p[i]) p[i] = 1;
        if (p[i] == 1) r1.push_back(i);
        else r2.push_back(i);
    }
    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[s1 - 1], r1[i]);
                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 ((int)r1.size() > (int)r2.size()) return r1;
    return r2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 178 ms 676 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 115 ms 344 KB Output is correct
4 Correct 391 ms 344 KB Output is correct
5 Correct 735 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 119 ms 340 KB Output is correct
4 Correct 373 ms 344 KB Output is correct
5 Correct 716 ms 680 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 119 ms 600 KB Output is correct
9 Correct 243 ms 844 KB Output is correct
10 Correct 761 ms 684 KB Output is correct
11 Correct 745 ms 684 KB Output is correct
12 Correct 778 ms 680 KB Output is correct
13 Correct 754 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 124 ms 344 KB Output is correct
4 Correct 382 ms 344 KB Output is correct
5 Correct 724 ms 680 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 122 ms 600 KB Output is correct
9 Correct 294 ms 456 KB Output is correct
10 Correct 749 ms 852 KB Output is correct
11 Correct 687 ms 684 KB Output is correct
12 Correct 760 ms 680 KB Output is correct
13 Correct 769 ms 852 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Incorrect 1 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Partially correct 111 ms 344 KB Output is partially correct
4 Partially correct 320 ms 344 KB Output is partially correct
5 Partially correct 776 ms 684 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 33 ms 344 KB Output is correct
8 Partially correct 118 ms 600 KB Output is partially correct
9 Partially correct 230 ms 592 KB Output is partially correct
10 Partially correct 714 ms 684 KB Output is partially correct
11 Partially correct 751 ms 680 KB Output is partially correct
12 Partially correct 744 ms 688 KB Output is partially correct
13 Partially correct 734 ms 684 KB Output is partially correct
14 Correct 8 ms 344 KB Output is correct
15 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -