답안 #1080323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080323 2024-08-29T08:50:27 Z Jawad_Akbar_JJ 기지국 (IOI20_stations) C++17
0 / 100
2 ms 600 KB
#include <iostream>
#include <vector>
 
using namespace std;
const int N1 = 1005;
vector<int> nei[N1];
int d[N1], num[N1], c = 0;
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;

	if (d[mx] <= 2){
		int cur;
		for (int i=0;i<n;i++)
			if (d[i] == 1)
				cur = i;
		dfs1(cur);
		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.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:55:1: warning: control reaches end of non-void function [-Wreturn-type]
   55 | }
      | ^
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:11:9: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   11 |  num[u] = c++;
      |  ~~~~~~~^~~~~
stations.cpp:32:7: note: 'cur' was declared here
   32 |   int cur;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Invalid labels (duplicates values). scenario=0, label=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -