이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int timer = 0;
int st[1005], ed[1005], dep[1005];
vector<int> edg[1005];
vector<int> ans;
vector< pair<int,int> > tmp;
void dfs(int x, int p) {
if(x==0) dep[x] = 0;
else dep[x] = dep[p]+1;
st[x] = ++timer;
for(int i:edg[x]) {
if(i!=p) {
dfs(i, x);
}
}
ed[x] = ++timer;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i=0; i<n; i++) edg[i].clear();
for(int i=0; i<n-1; i++) {
edg[u[i]].push_back(v[i]);
edg[v[i]].push_back(u[i]);
}
dfs(0, -1);
ans.resize(n);
tmp.clear();
for(int i=0; i<n; i++) {
if(dep[i]%2==0) ans[i] = st[i];
else ans[i] = ed[i];
tmp.push_back({ans[i], i});
}
sort(tmp.begin(), tmp.end());
for(int i=0; i<n; i++) {
ans[tmp[i].second] = i;
}
return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s == 0) {
sort(c.begin(), c.end());
for(int i=0; i<c.size(); i++) if(c[i]>=t) return c[i];
} else if(c[0] > s) { // s uses start time
sort(c.begin(), c.end());
if(t < s || t >= c[c.size()-1]) return c[c.size()-1];
for(int i=0; i<c.size()-1; i++) if(c[i]>=t) return c[i];
} else if(c[0] < s) { // s uses end time
sort(c.begin(), c.end());
if(t > s || c.size()==1 || t < c[1]) return c[0];
for(int i=1; i<c.size(); i++) if(i==c.size()-1 || t<c[i+1]) return c[i];
}
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0; i<c.size(); i++) if(c[i]>=t) return c[i];
| ~^~~~~~~~~
stations.cpp:51:17: 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=0; i<c.size()-1; i++) if(c[i]>=t) return c[i];
| ~^~~~~~~~~~~
stations.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=1; i<c.size(); i++) if(i==c.size()-1 || t<c[i+1]) return c[i];
| ~^~~~~~~~~
stations.cpp:55:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=1; i<c.size(); i++) if(i==c.size()-1 || t<c[i+1]) return c[i];
| ~^~~~~~~~~~~~
stations.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
57 | }
| ^
# | 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... |