Submission #413279

# Submission time Handle Problem Language Result Execution time Memory
413279 2021-05-28T12:26:01 Z SuhaibSawalha1 Stations (IOI20_stations) C++17
13 / 100
1099 ms 744 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<vector<int>> adj;
vector<int> lab;
int cnt;
 
void dfs (int u, int p = -1) {
	for (int v : adj[u]) {
		if (v ^ p) {
			dfs(v, u);
		}
	}
	lab[u] = cnt++;
}

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

bool subtask2 () {
	for (int i = 0; i < (int)adj.size(); ++i) {
		vector<int> y{(i - 1) / 2, 2 * i + 1, 2 * i + 2};
		if (!i) {
			y.erase(y.begin());
		}
		sort(adj[i].begin(), adj[i].end());
		while (y.size() > adj[i].size()) {
			y.pop_back();
		}
		if (y != adj[i]) {
			return 0;
		}
	}
	return 1;
}
 
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 (subtask2()) {
		iota(lab.begin(), lab.end(), 0);
		return lab;
	}
	if (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;
	}
	array<int, 2> p {0};
	for (int i = 0; i < n; ++i) {
		p = max(p, {(int)adj[i].size(), i});
	}
	int lb = 1e5;
	lab[p[1]] = lb;
	for (int v : adj[p[1]]) {
		lb += 1e5;
		dfs2(v, p[1], lb);
	}
	return lab;
}
 
int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) {
		return c[0];
	}
	if (s >= 1e5) {
		int o = 1e5;
		if (s / o == t / o) {
			return s - (t < s) + (t > s);
		}
		return s % o ? s - 1 : o;	
	}
	sort(c.begin(), c.end());
	vector<int> y{(s - 1) / 2, 2 * s + 1, 2 * s + 2};
	if (!s) {
		y.erase(y.begin());
	}
	while (y.size() > c.size()) {
		y.pop_back();
	}
	if (y != c) {
		return s - (t < s) + (t > s);
	}
	int e = t;
	while (e) {
		int p = (e - 1) / 2;
		if (p == s) {
			return e;
		}
		e = p;
	}
	return (s - 1) / 2;
}
# Verdict Execution time Memory Grader output
1 Correct 734 ms 532 KB Output is correct
2 Correct 503 ms 528 KB Output is correct
3 Correct 1020 ms 488 KB Output is correct
4 Correct 850 ms 472 KB Output is correct
5 Correct 711 ms 400 KB Output is correct
6 Correct 559 ms 528 KB Output is correct
7 Correct 502 ms 492 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 5 ms 476 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 520 ms 588 KB Output is correct
2 Correct 640 ms 528 KB Output is correct
3 Correct 1029 ms 400 KB Output is correct
4 Correct 703 ms 400 KB Output is correct
5 Correct 612 ms 492 KB Output is correct
6 Correct 617 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 522 ms 616 KB Output is correct
2 Correct 462 ms 520 KB Output is correct
3 Correct 1031 ms 464 KB Output is correct
4 Correct 821 ms 484 KB Output is correct
5 Correct 736 ms 564 KB Output is correct
6 Correct 473 ms 528 KB Output is correct
7 Correct 495 ms 488 KB Output is correct
8 Correct 3 ms 476 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Incorrect 722 ms 400 KB Wrong query response.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1099 ms 400 KB Output is correct
2 Correct 759 ms 528 KB Output is correct
3 Correct 748 ms 400 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 2 ms 476 KB Output is correct
7 Incorrect 662 ms 492 KB Wrong query response.
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 668 ms 688 KB Output is correct
2 Correct 512 ms 744 KB Output is correct
3 Correct 1001 ms 400 KB Output is correct
4 Correct 783 ms 400 KB Output is correct
5 Correct 750 ms 400 KB Output is correct
6 Correct 477 ms 528 KB Output is correct
7 Correct 529 ms 548 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 6 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 489 ms 520 KB Output is correct
12 Correct 546 ms 528 KB Output is correct
13 Correct 1015 ms 400 KB Output is correct
14 Correct 786 ms 484 KB Output is correct
15 Correct 637 ms 400 KB Output is correct
16 Correct 562 ms 528 KB Output is correct
17 Incorrect 779 ms 400 KB Wrong query response.
18 Halted 0 ms 0 KB -