# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
842018 | Tenis0206 | 가장 긴 여행 (IOI23_longesttrip) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "longesttrip.h"
const int nmax = 256;
int n;
std::vector<int> G[nmax + 5];
vector<int> r;
int d[nmax + 5];
void bfs(int nod)
{
queue<int> q;
for(int i=0;i<n;i++)
{
d[i] = 0;
}
d[nod] = 1;
q.push(nod);
while(!q.empty())
{
nod = q.front();
q.pop();
for(auto it : G[nod])
{
if(d[it])
{
continue;
}
d[it] = 1 + d[nod];
q.push(it);
}
}
for(int i=0;i<n;i++)
{
if(d[i] > d[nod])
{
nod = i;
}
}
vector<int> aux;
aux.push_back(nod);
while(d[nod]!=1)
{
for(auto it : G[nod])
{
if(d[it]==d[nod] - 1)
{
nod = it;
break;
}
}
aux.push_back(nod);
}
if(aux.size() > r.size())
{
r = aux;
}
}
std::vector<int> longest_trip(int N, int D)
{
n = N;
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(are_connected({i}, {j}))
{
G[i].push_back(j);
G[j].push_back(i);
}
}
}
for(int i=0;i<n;i++)
{
bfs(i);
}
return r;
}