답안 #370898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370898 2021-02-25T02:27:12 Z XEMPLI5 Traffic (IOI10_traffic) C++17
컴파일 오류
0 ms 0 KB
#include "traffic.h"
#include <bits/stdc++.h>

using namespace std;

int fans, mxN = 1e6
vector<vector<int>> g(mxN);
vector<int> citySize(mxN), subTreeSize(mxN), maxTraffic(mxN), people(mxN);

void dfs(int cur, int par){
	subTreeSize[cur] = citySize[cur];
	for(auto e: g[cur]) {
		if(e == par) return;
		dfs(e,par);
		subTreeSize[cur] += subTreeSize[e];
		people[cur] = max(people[cur], subTreeSize[e]);
	}
	people[cur] = max(people[cur], fans - subTreeSize[cur]);
}

	

int LocateCentre(int n, int p[], int s[], int d[]){
	for(int i=0; i<n; i++){
		g[s[i]].push_back(d[i]);
		g[d[i]].push_back(s[i]);
	}
	for(int i=0; i<n; i++) {
		fans += p[i];
		citiySize[i] = p[i];
	}
	dfs(0,0);
	int ans = 0, minPeople = 1e9;
	for(int i=0; i<n; i++){
		if(people[i] < minPeople) {
			minPeople = people[i];
			ans = i;
		}
	}
	return ans;
}
	
	
	
	
	
	
	

Compilation message

traffic.cpp:7:1: error: expected ',' or ';' before 'vector'
    7 | vector<vector<int>> g(mxN);
      | ^~~~~~
traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:12:14: error: 'g' was not declared in this scope
   12 |  for(auto e: g[cur]) {
      |              ^
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:25:3: error: 'g' was not declared in this scope
   25 |   g[s[i]].push_back(d[i]);
      |   ^
traffic.cpp:30:3: error: 'citiySize' was not declared in this scope; did you mean 'citySize'?
   30 |   citiySize[i] = p[i];
      |   ^~~~~~~~~
      |   citySize