Submission #604610

#TimeUsernameProblemLanguageResultExecution timeMemory
604610TigryonochekkStations (IOI20_stations)C++17
0 / 100
3 ms320 KiB
#include <iostream>
#include "stations.h"
#include <vector>
#define ll long long
using namespace std;
const int N = 1002;

vector<int> g[N];
vector<int> labels;

void dfs(int v) {
	for (int to : g[v]) {
		if (labels[to] < 0) {
			labels[to] = labels[v] + 1;
			dfs(to);
		}
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	labels.resize(n);
	fill(labels.begin(), labels.end(), -1);
	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]);
	}
	int cnt = 0;
	bool f = true;
	for (int i = 0; i < n; i++) {
		if (g[i].size() > 2) {
			f = false;
			labels[i] = 0;
			for (int to : g[i]) {
				labels[to] = cnt * 1000 + 1;
				cnt++;
				dfs(to);
			}
			break;
		}
	}
	if (f) {
		for (int i = 0; i < n; i++) {
			if (g[i].size() == 1) {
				labels[i] = 0;
				dfs(i);
			}
		}
	}
	/*for (int i = 0; i < n; i++) {
		cout << labels[i] << " ";
	}
	cout << endl;*/
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) 
		return c[0];
	if (s == 0) {
		t /= 1000;
		t *= 1000;
		t++;
		return t;
	}
	if (t == 0)
		return c[0];
	if (s / 1000 == t / 1000) {
		if (t > s)
			return c[1];
		else
			return c[0];
	}
	else {
		return c[0];
	}
}
/*
1 
5 1000 
4 2 
3 1 
0 2 
0 3 
5 
4 0 2 
2 4 4 
3 4 0 
0 1 3 
0 3 3 

1 
7 7 
0 1 
0 2 
1 3 
1 4 
2 5 
2 6 
4 
0 4 1 
1 4 4 
1 5 0 
3 5 1 

1 
7 1000000 
0 3 
1 4 
2 5 
3 6 
4 6 
5 6 
4 
6 0 3 
3 0 0 
3 6 6 
3 1 6 

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...