이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include<bits/stdc++.h>
#define H(x, y) hoursRequired(x, y)
#define A(x, y) attractionsBehind(x, y)
#define Sz(x) x.size()
using namespace std;
const int N = 1e5 + 10;
int dp[N], h[N], d[N], par[N];
bool mark[N];
vector<int> adj[N];
int dfs(int x, int p = 0) {
int res = x;
for(auto i : adj[x]) {
if(i == p) continue;
h[i] = h[x] + 1;
int u = dfs(i, x);
if(h[u] > h[res]) {
res = u;
}
}
return res;
}
vector<int> createFunTour(int N, int Q) {
for(int i = 1; i < N; i++) {
for(int j = 0; j < i; j++) {
if(H(i, j) == 1) {
adj[i].push_back(j), adj[j].push_back(i);
}
}
}
int s = dfs(0), t = 0;
queue<int> pq;
pq.push(s), mark[s] = 1, par[s] = s;
while(!pq.empty()) {
int p = pq.front(); pq.pop();
if(d[p] >= d[t]) {
t = p;
}
for(auto i : adj[p]) {
if(mark[i]) continue;
mark[i] = 1, d[i] = d[p] + 1, pq.push(i);
par[i] = p;
}
}
memset(mark, 0, sizeof(mark));
vector<vector<int> > vc;
vc.push_back({t}), mark[t] = 1;
int k = par[t];
while(k != s) {
if(Sz(adj[k]) == 2) {
vc.push_back({k}), mark[k] = 1;
k = par[k];
continue;
}
vector<int> st;
queue<int> pq;
pq.push(k), mark[k] = 1, d[k] = 0;
while(!pq.empty()) {
int p = pq.front(); pq.pop();
st.push_back(p);
for(auto i : adj[p]) {
if(mark[i] == 1 || i == par[k]) continue;
d[i] = d[p] + 1, mark[i] = 1, pq.push(i);
}
}
vc.push_back(st);
k = par[k];
}
vc.push_back({s});
memset(mark, 0, sizeof(mark));
vector<int> ans;
int r = Sz(vc) - 1, nu = 0;
for(int l = 0; l < r; nu++) {
if(nu & 1) {
mark[vc[l].back()] = 1;
ans.push_back(vc[l].back());
vc[l].pop_back();
if(vc[l].empty()) l++;
}
else {
mark[vc[r].back()] = 1;
ans.push_back(vc[r].back());
vc[r].pop_back();
if(vc[r].empty())
r--;
}
}
int ptr = 0;
while(!vc[r].empty() && ptr < Sz(vc[r])) {
ans.push_back(vc[r].back());
ans.pop_back();
if(ptr < Sz(vc[r])) {
ans.push_back(vc[r][ptr]);
ptr++;
}
}
/* for(auto i : ans) cout<<i <<" ";
cout<<endl;*/
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:101:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | while(!vc[r].empty() && ptr < Sz(vc[r])) {
| ^
fun.cpp:104:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | if(ptr < Sz(vc[r])) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |