답안 #395598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395598 2021-04-28T16:33:36 Z garnab27 Traffic (IOI10_traffic) C++17
컴파일 오류
0 ms 0 KB
#include <vector>
#define ll int64_t


vector<ll > sum;
vector<ll > ans;
vector<int> g[1000006];

ll dfs1(int u, int p) {
	sum[u] += P[u];

	for(int v: g[u]) {
		if(v != p) {
			sum[u] += dfs1(v, u);
		} 
	}

	return sum[u];
}

void dfs2(int u, int p, ll psum) {

	ans[u] = 0;
	ll csum = P[u];
	if(p != -1) {
		ans[u] = max(ans[u], psum);
		csum += psum;
	}
	for(int v: g[u]) {
		if(v != p) {
			csum += sum[v];
			ans[u] = max(ans[u], sum[v]);
		}
	}
	for(int v: g[u]) {
		if(v != p) {
			dfs2(v, u, csum - sum[v]);
		}
	}
}

int LocateCentre(int N, int pp[], int S[], int D[]) {
   	
   	sum.resize(N);
   	ans.resize(N);
   	for(int i=0;i<N-1;i++) {
   		g[S[i]].pb(D[i]);
   		g[D[i]].pb(S[i]);
   	}
   	dfs1(0, -1);
   	dfs2(0, -1, 0);
   	int id = 0, mn = ans[0];
   	for(int i=1;i<N;i++) {
   		if(mn > ans[i]) {
   			mn = ans[i];
   			id = i;
   		}
   	}
   	return id;
}

Compilation message

traffic.cpp:5:1: error: 'vector' does not name a type
    5 | vector<ll > sum;
      | ^~~~~~
traffic.cpp:6:1: error: 'vector' does not name a type
    6 | vector<ll > ans;
      | ^~~~~~
traffic.cpp:7:1: error: 'vector' does not name a type
    7 | vector<int> g[1000006];
      | ^~~~~~
traffic.cpp:2:12: error: 'int64_t' does not name a type
    2 | #define ll int64_t
      |            ^~~~~~~
traffic.cpp:9:1: note: in expansion of macro 'll'
    9 | ll dfs1(int u, int p) {
      | ^~
traffic.cpp:2:12: error: 'int64_t' has not been declared
    2 | #define ll int64_t
      |            ^~~~~~~
traffic.cpp:21:25: note: in expansion of macro 'll'
   21 | void dfs2(int u, int p, ll psum) {
      |                         ^~
traffic.cpp: In function 'void dfs2(int, int, int)':
traffic.cpp:23:2: error: 'ans' was not declared in this scope
   23 |  ans[u] = 0;
      |  ^~~
traffic.cpp:2:12: error: 'int64_t' was not declared in this scope
    2 | #define ll int64_t
      |            ^~~~~~~
traffic.cpp:24:2: note: in expansion of macro 'll'
   24 |  ll csum = P[u];
      |  ^~
traffic.cpp:26:12: error: 'max' was not declared in this scope; did you mean 'std::max'?
   26 |   ans[u] = max(ans[u], psum);
      |            ^~~
      |            std::max
In file included from /usr/include/c++/9/vector:60,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: 'std::max' declared here
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
traffic.cpp:27:3: error: 'csum' was not declared in this scope; did you mean 'psum'?
   27 |   csum += psum;
      |   ^~~~
      |   psum
traffic.cpp:29:13: error: 'g' was not declared in this scope
   29 |  for(int v: g[u]) {
      |             ^
traffic.cpp:31:4: error: 'csum' was not declared in this scope; did you mean 'psum'?
   31 |    csum += sum[v];
      |    ^~~~
      |    psum
traffic.cpp:31:12: error: 'sum' was not declared in this scope; did you mean 'psum'?
   31 |    csum += sum[v];
      |            ^~~
      |            psum
traffic.cpp:32:13: error: 'max' was not declared in this scope; did you mean 'std::max'?
   32 |    ans[u] = max(ans[u], sum[v]);
      |             ^~~
      |             std::max
In file included from /usr/include/c++/9/vector:60,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: 'std::max' declared here
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
traffic.cpp:35:13: error: 'g' was not declared in this scope
   35 |  for(int v: g[u]) {
      |             ^
traffic.cpp:37:15: error: 'csum' was not declared in this scope; did you mean 'psum'?
   37 |    dfs2(v, u, csum - sum[v]);
      |               ^~~~
      |               psum
traffic.cpp:37:22: error: 'sum' was not declared in this scope; did you mean 'psum'?
   37 |    dfs2(v, u, csum - sum[v]);
      |                      ^~~
      |                      psum
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:44:5: error: 'sum' was not declared in this scope
   44 |     sum.resize(N);
      |     ^~~
traffic.cpp:45:5: error: 'ans' was not declared in this scope
   45 |     ans.resize(N);
      |     ^~~
traffic.cpp:47:6: error: 'g' was not declared in this scope
   47 |      g[S[i]].pb(D[i]);
      |      ^
traffic.cpp:50:5: error: 'dfs1' was not declared in this scope; did you mean 'dfs2'?
   50 |     dfs1(0, -1);
      |     ^~~~
      |     dfs2