Submission #432637

# Submission time Handle Problem Language Result Execution time Memory
432637 2021-06-18T11:53:38 Z saleh Stations (IOI20_stations) C++17
Compilation error
0 ms 0 KB
#include "stations.h"
#include <bits/stdc++.h>


using namespace std;

const int MAXN = 1000 + 23;

vector<int> g[MAXN];
int such;
vector<int> labels;

int dfs(int v, int p = -1, int nat = -1) {
	if (v == such) return nat;
	for (auto i : g[v]) if (i != p) {
		if (p == -1) {
			int tmp = dfs(i, v, i);
			if (tmp != -1) return tmp;
		}
		else {
			int tmp = dfs(i, v, nat);
			if (tmp != -1) return tmp;
		}
	}
	return -1;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	labels.clear();
	for (int i = 0; i < n; i++) labels.push_back(i);
	return labels;
//	cout << "learn" << endl;
	for (int i = 0; i < n; i++) g[i].clear();
	///.
	cnt = 0;
	for (int i = 0; i < n; i++) labels.push_back(0);
	for (int i = 0; i < n - 1; i++) {
		g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]);
	}
	for (int i = 0; i < n; i++) if (g[i].size() == 1) {
		dfs(i);
		break;
	}
//	assert(labels.size() == n);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	such = t;
	for (int i = 0; i < n - 1; i++) g[i / 2].push_back(i + 1), g[i + 1].push_back(i / 2);
	return dfs(s, t);
}
/*
int main() {
	for (auto i : label(3, 8, {0, 1}, {1, 2})) cout << i << endl;
	return 0;
}*/

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:35:2: error: 'cnt' was not declared in this scope; did you mean 'int'?
   35 |  cnt = 0;
      |  ^~~
      |  int
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:50:22: error: 'n' was not declared in this scope
   50 |  for (int i = 0; i < n - 1; i++) g[i / 2].push_back(i + 1), g[i + 1].push_back(i / 2);
      |                      ^