이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
const int N=1e3;
int l[N], r[N];
vector<int> adj[N];
int nxt=0;
int col[N];
void dfs(int u, int p, int c) {
col[u]=c;
l[u]=nxt++;
for(auto&v:adj[u]) {
if (v==p) continue;
dfs(v,u,!c);
}
r[u]=nxt++;
}
vector<int> label(int n, int k, vector<int>u, vector<int> v) {
forn(i,n) adj[i].clear(); nxt=0;
forn(i,n-1) {
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0,-1,0);
vector<int> ans(n);
forn(i,n) {
if (col[i]) {
ans[i]=l[i];
} else {
ans[i]=r[i];
}
}
set<int> s; forn(i,n) s.insert(ans[i]);
int mex=0;
map<int,int> c;
for(auto&x:s) c[x]=mex++;
forn(i,n) ans[i]=c[ans[i]];
return ans;
}
int is_ancestor(int l, int r, int y) {
//x is anc of y
return l <= y && y <= r;
}
int find_next_station(int s, int t, vector<int> adj) {
//cout<<"? "<<s<<' '<<t<<": "; for(auto&x:adj) cout<<x<<' '; cout<<'\n';
if (adj.size()==1) return adj[0];
if (s > adj.back()) {
int l=adj[1]-1;
int r=s;
if (is_ancestor(l,r,t)) {
for (int i=1; i<adj.size()-1; ++i) {
int l=adj[i], r=adj[i+1]-1;
if (is_ancestor(l,r,t)) return adj[i];
}
return adj.back();
} else {
return adj[0];
}
} else {
int l=s;
int r=adj[adj.size()-2]+1;
if (is_ancestor(l,r,t)) {
for (int i=1; i<adj.size()-1; ++i) {
int l=adj[i-1]+1, r=adj[i];
if (is_ancestor(l,r,t)) return adj[i];
}
return adj[0];
} else {
return adj.back();
}
}
assert(0);
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:4:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
4 | #define forn(i,n) for(int i=0;i<n;++i)
| ^~~
stations.cpp:25:2: note: in expansion of macro 'forn'
25 | forn(i,n) adj[i].clear(); nxt=0;
| ^~~~
stations.cpp:25:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
25 | forn(i,n) adj[i].clear(); nxt=0;
| ^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i=1; i<adj.size()-1; ++i) {
| ~^~~~~~~~~~~~~
stations.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i=1; i<adj.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... |