답안 #408449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408449 2021-05-19T07:30:01 Z muhammad_hokimiyon 기지국 (IOI20_stations) C++14
컴파일 오류
0 ms 0 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>

using namespace std;

const int N = 1e3 + 7;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	vector<int> g[n + 7];
	for(int i = 0; i < n - 1; i++){
        int x = u[i], y = v[i];
        g[x].push_back(y);
        g[y].push_back(x);
	}
	int st = 0;
	for(int i = 1; i < n; i++){
        if((int)g[i].size() < (int)g[st].size()){
            st = i;
        }
	}
	auto dfs = [&](int x, int p){
        for(auto y : g[x]){
            if(y == p)continue;
            d[y] = d[x] + 1;
            dfs(y, x);
        }
	}
	for(int i = 0; i < n; i++){
        labels[i] = d[i];
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    for(auto x : c){
        if(s < t && x > s)return x;
        if(s > t && x < s)return x;
    }
    return c[0];
}

Compilation message

stations.cpp: In lambda function:
stations.cpp:26:13: error: 'd' was not declared in this scope
   26 |             d[y] = d[x] + 1;
      |             ^
stations.cpp:27:13: error: use of 'dfs' before deduction of 'auto'
   27 |             dfs(y, x);
      |             ^~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:30:2: error: expected ',' or ';' before 'for'
   30 |  for(int i = 0; i < n; i++){
      |  ^~~
stations.cpp:30:17: error: 'i' was not declared in this scope
   30 |  for(int i = 0; i < n; i++){
      |                 ^