이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF = 1e9;
int n;
int sz[MAXN];
int pos[MAXN];
int type[MAXN];
int perm[MAXN];
int depth[MAXN];
std::vector <int> g[MAXN];
int waitlistType = -1;
void calcSize(int node, int par)
{
sz[node] = 1;
for (const int &u : g[node])
{
if (u == par)
{
continue;
}
calcSize(u, node);
sz[node] += sz[u];
}
}
int findCentroid(int node, int par)
{
for (const int &u : g[node])
{
if (u != par && sz[u] > n / 2)
{
return findCentroid(u, node);
}
}
return node;
}
void assign(int node, int par, int t)
{
type[node] = t;
depth[node] = depth[par] + 1;
for (const int &u : g[node])
{
if (u == par)
{
continue;
}
assign(u, node, t);
}
}
std::vector <int> createFunTour(int N, int Q)
{
n = N;
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 2 ; j <= n ; ++j)
{
if (hoursRequired(i - 1, j - 1) == 1)
{
g[i].push_back(j);
g[j].push_back(i);
}
}
}
calcSize(1, 0);
int cntr = findCentroid(1, 0);
for (int idx = 0 ; idx < g[cntr].size() ; ++idx)
{
assign(g[cntr][idx], cntr, idx);
}
std::iota(perm + 1, perm + 1 + n, 1);
std::sort(perm + 1, perm + 1 + n, [&](int x, int y)
{
return type[x] < type[y] || (type[x] == type[y] && depth[x] > depth[y]);
});
std::iota(pos + 1, pos + 1 + n, 0);
std::sort(pos + 1, pos + 1 + n, [&](int x, int y)
{
if ((x & 1) != (y & 1)) return (x & 1) < (y & 1);
return x < y;
});
std::vector <int> answer(n);
for (int i = 1 ; i <= n ; ++i)
{
answer[pos[i]] = perm[i] - 1;
}
return answer;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:83:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int idx = 0 ; idx < g[cntr].size() ; ++idx)
| ~~~~^~~~~~~~~~~~~~~~
# | 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... |