답안 #342398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342398 2021-01-02T05:10:32 Z Ta180m 기지국 (IOI20_stations) C++17
0 / 100
842 ms 1268 KB
#include "stations.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 1e3+5;

int cnt, in[MX], out[MX];
vector<int> labels, G[MX];

void dfs(int u, int p, int d) {
	in[u] = cnt++;
	for (int v : G[u]) if (v != p) dfs(v, u, d+1);
	out[u] = cnt++;
	labels[u] = (d%2 == 0 ? in[u] : out[u]);
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for (int i = 0; i < n; ++i) G[i].clear();
	for (int i = 0; i < n-1; ++i)
		G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
	labels.resize(n, 0);
	cnt = 1;
	dfs(0, -1, 0);
	// for (int x : labels) cout << x << '\n';
	vector<int> tmp(begin(labels), end(labels));
	sort(begin(tmp), end(tmp));
	for (int i = 0; i < labels.size(); ++i)
		labels[i] = lower_bound(begin(tmp), end(tmp), labels[i])-begin(tmp);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	/*unordered_map<int, int> in, out;
	if (s < *min_element(begin(c), end(c))) {
		in[s] = s;
		for (int i = 0; i < c.size(); ++i) out[c[i]] = c[i];
		if (in[s] == 0) {
			// s is root
			for (int i = 0; i < c.size(); ++i) {
				if (t <= out[c[i]]) return c[i];
			}
		}
		else {
			int p = *max_element(begin(c), end(c));
			c.erase(find(begin(c), end(c), p));
			in[c[0]] = in[s]+1;
			for (int i = 1; i < c.size(); ++i) in[c[i]] = out[c[i-1]]+1;
			out[s] = out[c.back()]+1;
			for (int i = 0; i < c.size(); ++i) {
				if (t > in[c[i]] && t < out[c[i]]) return c[i];
			}
			return p;
		}
	}
	else {
		out[s] = s;
		for (int i = 0; i < c.size(); ++i) in[c[i]] = c[i];
		int p = *min_element(begin(c), end(c));
		c.erase(find(begin(c), end(c), p));
		in[s] = in[c[0]]-1;
		for (int i = 0; i < c.size()-1; ++i) out[c[i]] = in[c[i+1]]-1;
		out[c.back()] = out[s]-1;
		for (int i = 0; i < c.size(); ++i) {
			if (t > in[c[i]] && t < out[c[i]]) return c[i];
		}
		return p;
	}*/
	// cout << s << ' ' << t;
	// for (int x : c) cout << ' ' << x;
	// cout << '\n';
	return c.back();
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 0; i < labels.size(); ++i)
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 529 ms 1268 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 468 ms 880 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 544 ms 864 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 842 ms 944 KB Output is correct
2 Incorrect 624 ms 944 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 503 ms 992 KB Wrong query response.
2 Halted 0 ms 0 KB -