답안 #948732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948732 2024-03-18T12:47:17 Z thinknoexit 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
752 ms 680 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]++;
        }
    }
    queue<int> q;
    for (int i = 0;i < n;i++) {
        if (deg[i] == n - 1) continue;
        q.push(i);
        p[i] = 1;
        break;
    }
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 0;i < n;i++) {
            if (!p[i] && !adj[v][i]) {
                p[i] = 3 - p[v];
                q.push(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;
    int s1 = r1.size(), s2 = r2.size();
    bool ch = 0;
    for (int i = 0;i < s1;i++) {
        for (int j = 0;j < s2;j++) {
            if (adj[r1[i]][r2[j]]) {
                ch = 1;
                swap(r1[s1 - 1], r1[i]);
                swap(r2[0], r2[j]);
                break;
            }
        }
    }
    if (!ch) {
        if ((int)r1.size() > (int)r2.size()) return r1;
        return r2;
    }
    vector<int> ans;
    for (auto& x : r1) ans.push_back(x);
    for (auto& x : r2) ans.push_back(x);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 174 ms 680 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 122 ms 596 KB Output is correct
4 Correct 345 ms 344 KB Output is correct
5 Correct 715 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 123 ms 344 KB Output is correct
4 Correct 366 ms 344 KB Output is correct
5 Correct 750 ms 676 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Incorrect 1 ms 344 KB Incorrect
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 123 ms 344 KB Output is correct
4 Correct 359 ms 344 KB Output is correct
5 Correct 752 ms 680 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Incorrect 1 ms 344 KB Incorrect
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 27 ms 344 KB Output is correct
3 Partially correct 115 ms 344 KB Output is partially correct
4 Partially correct 366 ms 344 KB Output is partially correct
5 Partially correct 705 ms 680 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Incorrect 1 ms 344 KB Incorrect
8 Halted 0 ms 0 KB -