답안 #948766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948766 2024-03-18T13:27:56 Z thinknoexit 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
788 ms 796 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));
    vector<int> deg(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]) 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++) adj[i].clear();
    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 (int k = 0;k < s1;k++) ans.push_back(r1[i]);
                for (int k = 0;k < s2;k++) ans.push_back(r2[i]);
                return ans;
            }
        }
    }
    if (r1.size() > r2.size()) return r1;
    return r2;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Incorrect
2 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 Correct 143 ms 344 KB Output is correct
4 Correct 348 ms 484 KB Output is correct
5 Correct 788 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 22 ms 596 KB Output is correct
3 Correct 137 ms 344 KB Output is correct
4 Correct 374 ms 592 KB Output is correct
5 Correct 729 ms 596 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 127 ms 796 KB Output is correct
4 Correct 330 ms 488 KB Output is correct
5 Correct 771 ms 600 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 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 124 ms 344 KB Output is partially correct
4 Partially correct 381 ms 500 KB Output is partially correct
5 Partially correct 743 ms 600 KB Output is partially correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -