Submission #1080349

# Submission time Handle Problem Language Result Execution time Memory
1080349 2024-08-29T09:01:02 Z Jawad_Akbar_JJ Stations (IOI20_stations) C++17
0 / 100
3000 ms 2097152 KB
#include <iostream>
#include <vector>
 
using namespace std;
const int N1 = 1005;
vector<int> nei[N1];
int d[N1], num[N1], c;
bool seen[N1];

void dfs1(int u, int p = -1){
	num[u] = c++;
	for (int i : nei[u])
		if (i != p)
			dfs1(i, u);
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
	for (int i=0;i<n-1;i++){
		nei[u[i]].push_back(v[i]);
		nei[v[i]].push_back(u[i]);
		d[u[i]]++;
		d[v[i]]++;
	}
	vector<int> lab(n, 0);

	int mx = 0;
	for (int i=0;i<n;i++)
		if (d[i] > d[mx])
			mx = i;

	int cr = 0;
	if (d[mx] > 2){
		for (int i : nei[mx])
			c = cr * 1000, cr++, dfs1(i, mx);
		num[mx] = 1e6;
		for (int i=0;i<n;i++)
			lab[i] = num[i];
		return lab;
	}
 
	return lab;
 
}
 
int find_next_station(int s, int t, vector<int> lab){
	if (lab.size() == 1)
		return lab[0];
	if (lab[0] == t or lab[1] == t)
		return t;
	
	if (s == 1e6){
		int lst = lab[0];
		for (int i : lab){
			if (i > t)
				return lst;
			lst = i;
		}
		return lst;
	}

	if (t == 1e6){
		return lab[0];
	}
	if (s / 1000 != t / 1000){
		if (lab[1] == 1e6)
			return lab[1];
		return lab[0];
	}

	if (lab.size() == 2){
		if (abs(lab[0] - t) < abs(lab[1] - t))
			return lab[0];
		return lab[1];
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
   75 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 1675 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1970 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Invalid labels (duplicates values). scenario=0, label=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3100 ms 1999772 KB Time limit exceeded
2 Halted 0 ms 0 KB -