이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
using namespace std;
int sz;
vector<vector<int>> g;
vector<int> labels;
int cnt = 0;
void dfs(int v, int p)
{
int tin = cnt++;
for (int to : g[v])
{
if (to == p)
continue;
dfs(to, v);
}
int tout = cnt++;
labels[v] = (tin % 2 == 0 ? tin : tout) / 2;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
labels = vector<int>(n);
sz = n;
g = vector<vector<int>>(n);
cnt = 0;
for (int i = 0; i < n - 1; i++)
{
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0, -1);
return labels;
}
bool check(int tin, int tout, int m)
{
return tin <= m && tout >= m;
}
int find_next_station(int s, int t, vector<int> c) {
if (s > c[0])
{
if (!check(c[0], s, t))
return c[0];
for (int i = 1; i < c.size() - 1; i++)
{
if (check(c[i], c[i + 1] - 1, t))
return c[i];
}
return c[c.size() - 1];
}
else
{
if (!check(s, c[c.size() - 1], t))
return c[c.size() - 1];
for (int i = 1; i < c.size() - 1; i++)
{
if (check(c[i - 1] + 1, c[i], t))
return c[i];
}
return c[0];
}
}
/*
1
5 10
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3
*/
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 1; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
stations.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i = 1; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# | 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... |