Submission #413192

# Submission time Handle Problem Language Result Execution time Memory
413192 2021-05-28T11:01:32 Z SuhaibSawalha1 Stations (IOI20_stations) C++17
0 / 100
9 ms 912 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> adj;
vector<int> lab;
int cnt;
bool subtask1;

void dfs (int u, int p = -1) {
	for (int v : adj[u]) {
		if (v ^ p) {
			dfs(v, u);
		}
	}
	lab[u] = cnt++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	adj.assign(n, {});
	lab.resize(n);
	cnt = 0;
	for (int i = 0; i < n - 1; ++i) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	if ((subtask1 = all_of(adj.begin(), adj.end(), [](auto &e) {return e.size() < 3;}))) {
		for (int i = 0; i < n; ++i) {
			if (adj[i].size() == 1) {
				dfs(i);
				break;
			}
		}
		return lab;
	}
	iota(lab.begin(), lab.end(), 0);
	return lab;
}
 
int find_next_station(int s, int t, vector<int> c) {
	if (subtask1) {
		return s - (t < s) + (t > s);
	}
	set<int> p;
	int e = s;
	while (e) {
		p.insert(e);
		e = (e - 1) / 2;
	}
	if (p.count(t)) {
		return (s - 1) / 2; 
	}
	e = t;
	while (e) {
		int pa = (e - 1) / 2;
		if (p.count(pa)) {
			return e;
		}
		e = pa;
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:44:11: warning: control reaches end of non-void function [-Wreturn-type]
   44 |  set<int> p;
      |           ^
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 748 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 648 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 912 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 744 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -