답안 #306510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306510 2020-09-25T18:23:46 Z tengiz05 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include "grader.c"
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1e5+5;
bool used[N];
int depth[N];
int dp[N];
vector<pair<int, int>> edges[N];
vector<int> a[N];
// dfs for calculating dp. (dp[i] - maximum depth)
void dfs(int u, int p){
	used[u] = true;
	dp[u] = 0;
	a[u].push_back(0);a[u].push_back(0);
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		dfs(v, u);
		dp[u] = max(dp[u], dp[v]+cost);
		a[u].push_back(dp[v]+cost);
	}
	sort(a[u].begin(), a[u].end());
	reverse(a[u].begin(), a[u].end());
}
 
//dfs for rerooting
int mn;
void dfs2(int u, int p, int T){
	int dpu = dp[u];
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		int tmp = dp[v];
		if(dp[v]+cost == a[u][0])dp[u] = a[u][1];
		if(u != p)dp[u] = max(dp[u], dp[p] + T);
		dp[v] = max(dp[v], dp[u] + cost);
		mn = min(mn, dp[v]);
		dfs2(v, u, cost);
		dp[v] = tmp;
		dp[u] = dpu;
	}
}
 
//calculate best center for the tree
int calculate_center(int u){
	dfs(u, u);
	mn = dp[u];
	dfs2(u, u ,0);
	return mn;
}
int travelTime(int _N, int M, int L, int A[], int B[], int T[]) {
	n = _N;
	for(int i=0;i<M;i++){
		edges[A[i]].push_back({B[i], T[i]});
		edges[B[i]].push_back({A[i], T[i]});
	}
	vector<int> v;
	for(int i=0;i<n;i++){
		if(!used[i]){
			v.push_back(calculate_center(i));
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if(v.size() == 1){
		return a[0][0] + a[0][1];
	}
	else {
		int m = 0;
		for(int i=0;i<n;i++){
			m = max(m, a[i][0]+a[i][1]);
		}
		return max(v[0]+v[1]+L, max(m, ((v.size()>=3)? v[1]+v[2]+2*L : 0)));
	}
}

Compilation message

In file included from dreaming.cpp:2:
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
grader.c:9:4: error: expected unqualified-id before 'while'
    9 |  } while(0)
      |    ^~~~~
/usr/include/c++/9/bits/basic_ios.h: In member function 'std::basic_ios<_CharT, _Traits>::operator bool() const':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/ios:44,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/basic_ios.h:118:23: error: expected ';' before 'do'
  118 |       { return !this->fail(); }
      |                       ^
      |                       ;
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/basic_ios.h: In member function 'bool std::basic_ios<_CharT, _Traits>::operator!() const':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/ios:44,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/basic_ios.h:126:22: error: expected ';' before 'do'
  126 |       { return this->fail(); }
      |                      ^
      |                      ;
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/ostream.tcc: In member function 'std::basic_ostream<_CharT, _Traits>::pos_type std::basic_ostream<_CharT, _Traits>::tellp()':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/ostream:702,
                 from /usr/include/c++/9/istream:39,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/ostream.tcc:242:15: error: expected ')' before 'do'
  242 |    if (!this->fail())
      |       ~       ^
      |               )
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/ostream.tcc: In member function 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::seekp(std::basic_ostream<_CharT, _Traits>::pos_type)':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/ostream:702,
                 from /usr/include/c++/9/istream:39,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/ostream.tcc:263:15: error: expected ')' before 'do'
  263 |    if (!this->fail())
      |       ~       ^
      |               )
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/ostream.tcc: In member function 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::seekp(std::basic_ostream<_CharT, _Traits>::off_type, std::ios_base::seekdir)':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/ostream:702,
                 from /usr/include/c++/9/istream:39,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/ostream.tcc:295:15: error: expected ')' before 'do'
  295 |    if (!this->fail())
      |       ~       ^
      |               )
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/istream.tcc: In member function 'std::basic_istream<_CharT, _Traits>::pos_type std::basic_istream<_CharT, _Traits>::tellg()':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/istream:991,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/istream.tcc:835:19: error: expected ')' before 'do'
  835 |        if (!this->fail())
      |           ~       ^
      |                   )
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/istream.tcc: In member function 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::seekg(std::basic_istream<_CharT, _Traits>::pos_type)':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/istream:991,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/istream.tcc:865:19: error: expected ')' before 'do'
  865 |        if (!this->fail())
      |           ~       ^
      |                   )
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/istream.tcc: In member function 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::seekg(std::basic_istream<_CharT, _Traits>::off_type, std::ios_base::seekdir)':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/istream:991,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/istream.tcc:904:19: error: expected ')' before 'do'
  904 |        if (!this->fail())
      |           ~       ^
      |                   )
In file included from dreaming.cpp:2:
/usr/include/c++/9/bits/regex.tcc: In member function 'int std::__cxx11::regex_traits< <template-parameter-1-1> >::value(_Ch_type, int) const':
grader.c:6:23: error: expected unqualified-id before 'do'
    6 | #define fail(s, x...) do { \
      |                       ^~
In file included from /usr/include/c++/9/bits/regex.h:2870,
                 from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from dreaming.cpp:3:
/usr/include/c++/9/bits/regex.tcc:350:19: error: expected ';' before 'do'
  350 |       return __is.fail() ? -1 : __v;
      |                   ^
      |                   ;
/usr/include/c++/9/bits/regex.tcc:350:26: error: expected ';' before '?' token
  350 |       return __is.fail() ? -1 : __v;
      |                          ^
/usr/include/c++/9/bits/regex.tcc:350:26: error: expected primary-expression before '?' token