답안 #1000495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000495 2024-06-17T15:34:06 Z Mardonbekhazratov 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
2 ms 344 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;

using namespace std;

vector<int>sub1(int n){
    vector<int>ans;
    for(int i=0;i<n;i++) ans.push_back(i);
    return ans;
}

vector<vector<int>>v;

vector<int> longest_trip(int N, int D){
    if(D==3) return sub1(N);
    v.assign(N,vector<int>(0));
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(are_connected({i},{j})){
                v[i].push_back(j);
                v[j].push_back(i);
            }
        }
    }
    vector<vector<int>>ans(N);
    for(int i=0;i<N;i++){
        int mx=0,id=-1;
        vector<int>p(N);
        vector<bool>vis(N,false);
        p[i]=i;
        vector<int>dp(N,0);
        dp[i]=0;
        priority_queue<pair<int,int>>q;
        q.push({0,i});
        while(!q.empty()){
            int x=q.top().second;
            q.pop();
            vis[x]=true;
            for(int z:v[x]){
                if(!vis[z]){
                    dp[z]=dp[x]+1;
                    p[z]=x;
                    q.push({dp[z],z});
                }
            }
        }
        for(int j=0;j<N;j++){
            if(dp[j]>mx) mx=dp[j],id=j;
        }
        while(p[id]!=i){
            ans[i].push_back(id);
            id=p[id];
        }
    }
    int mx=0,id=0;
    for(int i=0;i<N;i++) if(ans[i].size()>mx) mx=ans[i].size(),id=i;
    return ans[id];
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:57:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |     for(int i=0;i<N;i++) if(ans[i].size()>mx) mx=ans[i].size(),id=i;
      |                             ~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -