이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
const int MAXN = 2e3+10;
const int MAX = 1e3;
int n, k;
vector <int> adj[MAXN], dw[MAXN];
vector <int> lab;
int chi[MAXN], val[MAXN], cnt;
void dfs(int nw, int par){ // build val, tergantung dfs
val[nw] = cnt++;
for(auto nx : adj[nw]){
if(nx == par) continue;
dw[nw].pb(nx);
dfs(nx, nw);
}
}
void bd(int nw, int par){
for(int i=0; i<dw[nw].size(); i++){
if(i+1==dw[nw].size()) chi[ dw[nw][i] ] = 0;
else { // ada nx nya
chi[ dw[nw][i] ] = val[ dw[nw][i+1] ]; // nx nya yg itu
}
}
for(auto nx : dw[nw]){
if(nx == par) continue;
bd(nx, nw);
}
}
vector<int> label(int N, int K, vector<int> u, vector<int> v) {
n = N; k = K;
lab.clear(); lab.resize(n); cnt = 0;
for(int i=0; i<=n; i++){
adj[i].clear(); dw[i].clear();
}
for(int i=0; i<n-1; i++){
adj[u[i]].pb(v[i]); adj[v[i]].pb(u[i]);
}
dfs(0, -1); bd(0, -1);
for(int i=0; i<n; i++) lab[i] = val[i] + chi[i]*MAX;
//for(int i=0; i<n; i++) cout << i << ' ' << val[i] << ' ' << chi[i] << " p\n";
return lab;
}
int find_next_station(int s, int t, vector<int> c) { // c sorted
int ans = -1;
if(s==0){ // s itu root
for(auto in : c){
if(in <= t) ans = in; // ambil yg terakhir -> in <=
}
return ans;
}
int nx = s/MAX; // kalo nx==0, brati gk ada nx
for(int i=1; i<c.size(); i++){
for(auto in : c){
if(in <= t) ans = in; // ambil yg terakhir -> in <=
}
}
if(t < c[1] || t >= nx) return c[0]; // parent
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'void bd(int, int)':
stations.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0; i<dw[nw].size(); i++){
| ~^~~~~~~~~~~~~~
stations.cpp:29:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(i+1==dw[nw].size()) chi[ dw[nw][i] ] = 0;
| ~~~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=1; i<c.size(); 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... |