답안 #1065129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065129 2024-08-18T23:56:46 Z vjudge1 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
871 ms 1420 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[256];
bitset<256>vis;
void dfs(int n){
    if(vis[n])return;
    vis[n]=1;
    for(auto i:adj[n])
        dfs(i);
}
vector<int>path;
void dfs2(int n){
    path.push_back(n);
    vis[n]=1;
    for(auto i:adj[n])
        if(!vis[i])
            return dfs2(i);
}
vector<int> longest_trip(int N, int D){
    for(int i=0;i<N;i++)
        adj[i].clear();
    for(int i=1;i<N;i++) for(int j=i;j--;)
        if(are_connected({i},{j}))
            adj[i].push_back(j),
            adj[j].push_back(i);
    vis.reset();
    dfs(0);
    if(vis.count()!=N){
        vector<int>a,b;
        for(int i=0;i<N;i++)
            if(!vis[i])
                a.push_back(i);
            else b.push_back(i);
        return a.size()>b.size()?a:b;
    }
    vis.reset();
    path.clear();
    dfs2(0);
    if(path.size()==N)
        return path;
    for(auto x:adj[0])
        if(!vis[x]) {
            vector<int>v2;
            vis[x]=1;
            for(int i=0;i<N;i++)
                if(!vis[i])v2.push_back(i);
            v2.push_back(x);
            for(auto i:path)
                v2.push_back(i);
            return v2;
        }
    return {};
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:29:19: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(vis.count()!=N){
      |        ~~~~~~~~~~~^~~
longesttrip.cpp:40:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     if(path.size()==N)
      |        ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 198 ms 1148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Correct 150 ms 344 KB Output is correct
4 Correct 415 ms 600 KB Output is correct
5 Correct 848 ms 1028 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 138 ms 344 KB Output is correct
4 Correct 406 ms 640 KB Output is correct
5 Correct 860 ms 964 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Correct 150 ms 344 KB Output is correct
9 Correct 323 ms 600 KB Output is correct
10 Correct 829 ms 1060 KB Output is correct
11 Correct 851 ms 736 KB Output is correct
12 Correct 870 ms 592 KB Output is correct
13 Correct 871 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 138 ms 600 KB Output is correct
4 Correct 416 ms 716 KB Output is correct
5 Correct 835 ms 1352 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Correct 155 ms 456 KB Output is correct
9 Correct 297 ms 344 KB Output is correct
10 Correct 811 ms 700 KB Output is correct
11 Correct 811 ms 968 KB Output is correct
12 Correct 844 ms 860 KB Output is correct
13 Correct 843 ms 1260 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 15 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Partially correct 149 ms 344 KB Output is partially correct
4 Partially correct 422 ms 456 KB Output is partially correct
5 Partially correct 827 ms 856 KB Output is partially correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Partially correct 151 ms 344 KB Output is partially correct
9 Partially correct 324 ms 600 KB Output is partially correct
10 Partially correct 868 ms 920 KB Output is partially correct
11 Partially correct 839 ms 984 KB Output is partially correct
12 Partially correct 830 ms 1420 KB Output is partially correct
13 Partially correct 871 ms 840 KB Output is partially correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -