이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "stations.h"
#warning That's not FB, that's my FB
using namespace std;
vector<int> g[1005];
int h[1005], pre[1005], post[1005], tmp, tmp2;
bool viz[1005];
void dfs(int nod, int tata)
{
viz[nod] = true;
//cout << "ya" << nod << endl;
if (h[nod] % 2 == 0)
{
tmp++;
pre[nod] = tmp;
}
for (auto vecin : g[nod])
{
if (vecin != tata)
{
h[vecin] = 1 + h[nod];
dfs(vecin, nod);
}
}
if (h[nod] % 2 == 1)
{
tmp++;
post[nod] = tmp;
}
}
vector<int> label (int n, int k, vector<int> u, vector<int> v)
{
for (int i = 0; i < n; i++)
g[i].clear(), viz[i] = false;
for (int i = 0; i < n - 1; i++)
g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]);
vector<int> ans(n);
h[0] = 0;
tmp = -1;
tmp2 = -1;
//cout << "ya" << endl;
dfs(0, -1);
//for (int i = 0; i < n; i++)
// cout << pre[i] << ' ' << post[i] << endl;
for (int i = 0; i < n; i++)
{
if (h[i] % 2 == 0)
ans[i] = pre[i];
else
ans[i] = post[i];
}
vector<pair<int,int>> pans;
for (int i = 0; i < n; i++)
pans.push_back({ans[i],i});
sort(pans.begin(), pans.end());
for (int i = 0; i < n; i++)
ans[pans[i].second] = i;
//for (int i = 0; i < n; i++)
// cout << ans[i] << '\n';
return ans;
}
int find_next_station(int s, int f, vector<int> c)
{
sort(c.begin(), c.end());
if (c.size() == 1)
return c[0];
if (s < c[0])
{
///pre
int mxf = c[c.size() - 2];
if (f > s and f <= mxf)
{
int pz;
for (int i = c.size() - 2; i >= 0; i--)
if (c[i] >= f)
pz = i;
return c[pz];
}
else
return c.back();
}
else
{
///post
int mnf = c[1];
if (f >= mnf and f < s)
{
int pz;
for (int i = 1; i < c.size(); i++)
if (c[i] <= f)
pz = i;
return c[pz];
}
else
return c[0];
}
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
3 | #warning That's not FB, that's my FB
| ^~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:94:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i = 1; i < c.size(); i++)
| ~~^~~~~~~~~~
stations.cpp:97:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
97 | return c[pz];
| ^
stations.cpp:82:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
82 | return c[pz];
| ^
# | 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... |