Submission #342400

# Submission time Handle Problem Language Result Execution time Memory
342400 2021-01-02T05:24:44 Z Ta180m Stations (IOI20_stations) C++17
0 / 100
2 ms 396 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 = 0;
	dfs(0, -1, 0);

	for (int i = 0; i < n; ++i) {
		cout << in[i] << ' ' << out[i] << '\n';
	}

	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);
	// for (int x : labels) cout << x << '\n';
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) return c[0];
	unordered_map<int, int> in, out;
	int m = *min_element(begin(c), end(c));
	if (s < m) {
		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));
			if (t < in[s]) return p;
			for (int i = 0; i < c.size(); ++i) {
				if (t <= out[c[i]]) return c[i];
			}
			// 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 = m;
		c.erase(find(begin(c), end(c), p));
		if (t > out[s]) return p;
		for (int i = c.size()-1; i >= 0; --i) {
			if (t >= in[c[i]]) return c[i];
		}
		// 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:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 0; i < labels.size(); ++i)
      |                  ~~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int i = 0; i < c.size(); ++i) out[c[i]] = c[i];
      |                   ~~^~~~~~~~~~
stations.cpp:51:22: 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(); ++i) {
      |                    ~~^~~~~~~~~~
stations.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    for (int i = 0; i < c.size(); ++i) {
      |                    ~~^~~~~~~~~~
stations.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 0; i < c.size(); ++i) in[c[i]] = c[i];
      |                   ~~^~~~~~~~~~
stations.cpp:44:26: warning: control reaches end of non-void function [-Wreturn-type]
   44 |  unordered_map<int, int> in, out;
      |                          ^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 396 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 396 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -