답안 #948767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948767 2024-03-18T13:32:21 Z thinknoexit 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
776 ms 1252 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];
void dfs(int 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));
    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);
        }
    }
    vector<int> r1, r2;
    for (int i = 0;i < n;i++) {
        if (!col[i]) {
            col[i] = 1;
            dfs(i);
        }
        if (col[i] == 1) r1.push_back(i);
        else r2.push_back(i);
    }
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 167 ms 1252 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 123 ms 344 KB Output is correct
4 Correct 382 ms 484 KB Output is correct
5 Correct 697 ms 600 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 118 ms 344 KB Output is correct
4 Correct 320 ms 488 KB Output is correct
5 Correct 766 ms 600 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 26 ms 344 KB Output is correct
8 Correct 123 ms 432 KB Output is correct
9 Correct 272 ms 592 KB Output is correct
10 Correct 684 ms 688 KB Output is correct
11 Correct 776 ms 692 KB Output is correct
12 Correct 759 ms 688 KB Output is correct
13 Correct 734 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 125 ms 344 KB Output is correct
4 Correct 336 ms 484 KB Output is correct
5 Correct 663 ms 600 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 116 ms 428 KB Output is correct
9 Correct 292 ms 476 KB Output is correct
10 Correct 739 ms 692 KB Output is correct
11 Correct 726 ms 696 KB Output is correct
12 Correct 751 ms 944 KB Output is correct
13 Correct 740 ms 688 KB Output is correct
14 Correct 6 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 23 ms 344 KB Output is correct
3 Partially correct 116 ms 344 KB Output is partially correct
4 Partially correct 368 ms 488 KB Output is partially correct
5 Partially correct 700 ms 600 KB Output is partially correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Partially correct 126 ms 432 KB Output is partially correct
9 Partially correct 284 ms 460 KB Output is partially correct
10 Partially correct 685 ms 692 KB Output is partially correct
11 Partially correct 713 ms 852 KB Output is partially correct
12 Partially correct 719 ms 852 KB Output is partially correct
13 Partially correct 757 ms 692 KB Output is partially correct
14 Correct 7 ms 344 KB Output is correct
15 Incorrect 1 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -