답안 #926948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926948 2024-02-14T05:40:55 Z ByeWorld 기지국 (IOI20_stations) C++14
0 / 100
523 ms 948 KB
#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];
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;
		dfs(nx, nw);
	}
}
void bd(int nw, int par){ // build nx (child)
	for(int i=0; i<adj[nw].size(); i++){
		if(i+1==adj[nw].size()) chi[adj[nw][i]] = 0;
		else { // ada nx nya
			chi[adj[nw][i]] = adj[nw][i+1]; // nx nya yg itu
		}
	}

	for(auto nx : adj[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();

	for(int i=0; i<n-1; i++){
		adj[u[i]].pb(v[i]); adj[v[i]].pb(u[i]);
	}

	dfs(1, -1);
	bd(1, -1); 
	for(int i=0; i<n; i++) lab[i] = val[i] + chi[i]*MAX;
	//for(int i=0; i<n; i++) cout << i << ' ' << lab[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;
}

Compilation message

stations.cpp: In function 'void bd(int, int)':
stations.cpp:26:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i=0; i<adj[nw].size(); i++){
      |               ~^~~~~~~~~~~~~~~
stations.cpp:27:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   if(i+1==adj[nw].size()) chi[adj[nw][i]] = 0;
      |      ~~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:66:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for(int i=1; i<c.size(); i++){
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 596 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=4, label=2001
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 572 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=5001
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 386 ms 948 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 523 ms 684 KB Output is correct
2 Incorrect 508 ms 684 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 372 ms 948 KB Wrong query response.
2 Halted 0 ms 0 KB -