| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1333960 | nguyen | 도서관 (JOI18_library) | C++20 | 0 ms | 0 KiB |
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
pair<int,int> adj[1005];
void Solve(int N)
{
for(int i=0;i<N;i++)
adj[i]={-1,-1};
for(int i=0;i<N;i++)
{
if(adj[i].second!=-1) continue;
int except = adj[i].first;
int nb = find_neighbor(N,i,except);
if(nb==-1) continue;
if(adj[i].first==-1) adj[i].first=nb;
else adj[i].second=nb;
if(adj[nb].first==-1) adj[nb].first=i;
else adj[nb].second=i;
}
vector<int> res;
vector<bool> vis(N,false);
int start=-1;
for(int i=0;i<N;i++)
{
int deg=0;
if(adj[i].first!=-1) deg++;
if(adj[i].second!=-1) deg++;
if(deg==1)
{
start=i;
break;
}
}
while(start!=-1)
{
res.push_back(start+1);
vis[start]=true;
int next=-1;
if(adj[start].first!=-1 && !vis[adj[start].first])
next=adj[start].first;
else if(adj[start].second!=-1 && !vis[adj[start].second])
next=adj[start].second;
start=next;
}
Answer(res);
}