제출 #1143516

#제출 시각아이디문제언어결과실행 시간메모리
1143516hhvbTriumphal arch (POI13_luk)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; queue<int> q; vector< pair<int, int> > m; long long need[300001] int h[300001]; bool used[300001]; vector<int> adj[300001]; int main() { int n, u, v, adancime, k; int i; cin >> n; for ( i= 0; i < n - 1; i ++ ) { cin >> u >> v; adj[u].push_back( v ); adj[v].push_back( u ); } q.push( 1 ); used[1] = true; m.push_back( {0, 1} ); adancime = 0; h[1] = 0; while ( !q.empty() ) { u = q.front(); for ( i = 0; i < adj[u].size(); i ++ ) { if ( used[ adj[u][i] ] == false ) { q.push( adj[u][i] ); v = h[u] + 1; h [ adj[u][i] ] = v; m.push_back( make_pair( v, adj[u][i] ) ); used[adj[u][i]] = true; if ( v > adancime ) adancime = v; } } q.pop(); } sort ( m.begin(), m.end() ); int l, r, j; l = 0; r = 300000; if ( n == 1 ) { cout << 0; } else if ( n == 2 ) { cout << 1; }else { while ( l + 1 < r ) { k = (l + r) / 2; for ( i = n - 1; i >= 0; i -- ){ u = m[i].second; if ( m[i].first == adancime ) { need[u] = 0; } else { for ( j = 0; j < adj[u].size(); j ++ ) { if ( h[ adj[u][j] ] > h[u] ) need[u] = need[u] + need[ adj[u][j] ] + 1; } need[u] -= k; if ( need[u] < 0 ) need[u] = 0; } } if ( need[1] > 0 ) { l = k; } else { r = k; } } cout << l << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

luk.cpp:8:1: error: expected initializer before 'int'
    8 | int h[300001];
      | ^~~
luk.cpp: In function 'int main()':
luk.cpp:28:5: error: 'h' was not declared in this scope
   28 |     h[1] = 0;
      |     ^
luk.cpp:59:13: error: 'need' was not declared in this scope
   59 |             need[u] = 0;
      |             ^~~~
luk.cpp:64:21: error: 'need' was not declared in this scope
   64 |                     need[u] = need[u] + need[ adj[u][j] ] + 1;
      |                     ^~~~
luk.cpp:66:13: error: 'need' was not declared in this scope
   66 |             need[u] -= k;
      |             ^~~~
luk.cpp:71:10: error: 'need' was not declared in this scope
   71 |     if ( need[1] > 0 ) {
      |          ^~~~