답안 #948752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948752 2024-03-18T13:07:59 Z thinknoexit 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
766 ms 860 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()) {
        vector<int> udp;
        for (auto& i : rem) {
            q.push(i);
            p[i] = 1;
            rem.erase(i);
            break;
        }
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            udp.push_back(v);
            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);
        }
        bool ch = 0;
        for (int i = 0;i < n;i++) {
            for (int j = 0;j < n;j++) {
                if (!p[i] || !p[j]) continue;
                if (adj[i][j] && p[i] != p[j]) {
                    ch = 1;
                    break;
                }
            }
        }
        if (ch) for (auto& i : udp) p[i] = 3 - p[i];
    }
    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 166 ms 684 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 124 ms 344 KB Output is correct
4 Correct 345 ms 344 KB Output is correct
5 Correct 725 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 119 ms 344 KB Output is correct
4 Correct 348 ms 344 KB Output is correct
5 Correct 669 ms 680 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 117 ms 448 KB Output is correct
9 Correct 273 ms 456 KB Output is correct
10 Correct 685 ms 680 KB Output is correct
11 Correct 742 ms 684 KB Output is correct
12 Correct 678 ms 680 KB Output is correct
13 Correct 696 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 125 ms 344 KB Output is correct
4 Correct 346 ms 344 KB Output is correct
5 Correct 729 ms 676 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 118 ms 600 KB Output is correct
9 Correct 278 ms 456 KB Output is correct
10 Correct 748 ms 676 KB Output is correct
11 Correct 713 ms 692 KB Output is correct
12 Correct 755 ms 680 KB Output is correct
13 Correct 765 ms 860 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 596 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Partially correct 111 ms 344 KB Output is partially correct
4 Partially correct 366 ms 344 KB Output is partially correct
5 Partially correct 708 ms 676 KB Output is partially correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Partially correct 120 ms 448 KB Output is partially correct
9 Partially correct 257 ms 472 KB Output is partially correct
10 Partially correct 674 ms 676 KB Output is partially correct
11 Partially correct 745 ms 676 KB Output is partially correct
12 Partially correct 675 ms 680 KB Output is partially correct
13 Partially correct 766 ms 680 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -