답안 #1007061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007061 2024-06-24T11:18:19 Z Younis_Dwai 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
2 ms 388 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
vector<int> adj[505];
vector<int> v;
int mx=0,dis[505],n;
void perform(int node){
     for(int i=0;i<=n;i++) dis[i]=1e9;
     dis[node]=0;
     queue<int> q;
     q.push(node);
     while(!q.empty()){
            int node=q.front();
            q.pop();
            for(auto u : adj[node]){
                if(dis[u]>1+dis[node]){
                   dis[u]=1+dis[node];
                   q.push(node);
                }
            }
     }
     int bb=0,nd;
     for(int i=0;i<=n;i++){
         if(dis[i]+1>=mx){
            mx=dis[i];
            nd=i;
         }
     }
     while(nd!=node){
           for(auto u : adj[nd]){
                if(dis[u]==dis[nd]-1){
                    nd=u;
                }
           }
     }
     v.clear();
     v.pb(node);

     return ;
}
std::vector<int> longest_trip(int N, int D){
    n=N-1;
    v.clear();
    if(D==1){
        for(int i=0;i<N;i++) v.push_back(i);
        return v;
    }
    for(int i=0;i<N;i++) adj[i].clear();
    mx=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j) continue ;
            bool c=are_connected({i},{j});
            if(c==1){
              adj[i].pb(j);
              adj[j].pb(i);
            }
        }
    }
    for(int i=0;i<N;i++){
        perform(i);
    }
    return v;
}

Compilation message

longesttrip.cpp: In function 'void perform(int)':
longesttrip.cpp:23:10: warning: unused variable 'bb' [-Wunused-variable]
   23 |      int bb=0,nd;
      |          ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 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 -
# 결과 실행 시간 메모리 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
6 Incorrect 0 ms 344 KB Incorrect
7 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 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 388 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -