Submission #429455

# Submission time Handle Problem Language Result Execution time Memory
429455 2021-06-16T00:14:48 Z abdzag Stations (IOI20_stations) C++17
0 / 100
1067 ms 656 KB
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include "stations.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 2e9;

using namespace std;
vector<vector<ll>> children;
vector<bool> visited2;
vector<ll> in;
vector<ll> out;
ll counter = 0;
ll counter2 = 500;
void dfs(vector<int>& ans, ll cur, ll depth) {
	if (visited2[cur])return;
	visited2[cur] = 1;
	if (depth % 2 == 0)in[cur] = counter++;
	trav(a, children[cur]) {
		dfs(ans, a, depth + 1);
	}
	if (depth % 2)out[cur] = counter2++;
	if (depth % 2 == 0) {
		ans[cur] = in[cur];
	}
	else ans[cur] = out[cur];
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	ll counter = 0;
	vector<vector<ll>> g(n);
	rep(i, 0, n - 1) {
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	vector<int> ans(n);
	children.clear();
	visited2.clear();
	in.clear();
	out.clear();
	in.resize(n);
	out.resize(n);
	children.resize(n);
	visited2.resize(n);
	vector<int> visited(n);
	queue<ll> q;
	q.push(0);
	visited[0] = 1;
	while (!q.empty()) {
		ll cur = q.front();
		q.pop();
		trav(a, g[cur]) {
			if (!visited[a]) {
				visited[a] = 1;
				q.push(a);
				children[cur].push_back(a);
			}
		}
	}
	dfs(ans, 0, 0);
	return ans;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c[0] < s) {
		ll last = s;
		reverse(all(c));
		rep(i, 1, c.size()) {
			ll curout = last - 1;
			last = c[i];
			if (c[i] < t && t < curout) {
				return c[i];
			}
		}
		return c[0];
	}
	ll last = 0;
	rep(i, 0, c.size()) {
		ll curin = last + 1;
		last = c[i];
		if (curin < t && t < c[i]) {
			return c[0];
		}
	}
	return c[0];
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:38:5: warning: unused variable 'counter' [-Wunused-variable]
   38 |  ll counter = 0;
      |     ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 404 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1002
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 488 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=2, label=1154
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 586 ms 656 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1067 ms 468 KB Output is correct
2 Incorrect 951 ms 488 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 468 KB Invalid labels (duplicates values). scenario=7, label=1556
2 Halted 0 ms 0 KB -