답안 #720248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720248 2023-04-07T18:05:05 Z jcelin Islands (IOI08_islands) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define PB push_back
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
const ll INF = 1e18;

bool bio[MAXN];
int to[MAXN], w[MAXN]; 
vi g[MAXN];
ll ans, ret;
vll dp, s;

int ciklus(int u){
	if(bio[u]) return u;
	bio[u] = 1;
	int v = ciklus(to[u]);
	if(v){
		dp.PB(u);
		s.PB(w[u]);
		if(u == v) return 0;
		return v;
	}
	bio[u] = 0;
	return 0;
}

ll dfs(int u){
	ll mx = 0;
	bio[u] = 1;
	for(int x : g[u]){
		if(bio[x]) continue;
		ll ch = (ll)w[x] + dfs(x);
		ret = max(ret, (ll)ch + (ll)mx);
		mx = max(mx, ch);
	}
	return mx;
}

void resi(int u){
	dp.clear(), s.clear();
	ciklus(u);
	int sz = s.size();
	reverse(all(dp));
	reverse(all(s));
	for(ll &x : dp) x = (ll)dfs(x);
	for(int i = sz - 1; i; i--) swap(s[i], s[i - 1]);
	FOR(i, 1, sz) s[i] += s[i - 1];
	ll m1 = -INF, m2 = -INF;
	REP(i, sz){
		ret = max(ret, (ll)dp[i] + (ll)s[i] + (ll)m1);
		ret = max(ret, (ll)s[sz - 1] + (ll)m2 + (ll)dp[i] - (ll)s[i]);
		m1 = max(m1, (ll)dp[i] - (ll)s[i]);
		m2 = max(m2, (ll)dp[i] + (ll)s[i]);
	}
}

void solve(){
	int n;
	cin >> n;
	FOR(i, 1, n + 1) cin >> to[i] >> w[i], g[to[i]].PB(i); 
	FOR(i, 1, n + 1) if(!bio[i]) ret = 0, resi(i), ans += ret;
	cout << ans << "\n";
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solve();
	return 0;
}




Compilation message

islands.cpp:22:10: error: 'MAXN' was not declared in this scope
   22 | bool bio[MAXN];
      |          ^~~~
islands.cpp:23:8: error: 'MAXN' was not declared in this scope
   23 | int to[MAXN], w[MAXN];
      |        ^~~~
islands.cpp:23:17: error: 'MAXN' was not declared in this scope
   23 | int to[MAXN], w[MAXN];
      |                 ^~~~
islands.cpp:24:6: error: 'MAXN' was not declared in this scope
   24 | vi g[MAXN];
      |      ^~~~
islands.cpp: In function 'int ciklus(int)':
islands.cpp:29:5: error: 'bio' was not declared in this scope
   29 |  if(bio[u]) return u;
      |     ^~~
islands.cpp:30:2: error: 'bio' was not declared in this scope
   30 |  bio[u] = 1;
      |  ^~~
islands.cpp:31:17: error: 'to' was not declared in this scope; did you mean 'tm'?
   31 |  int v = ciklus(to[u]);
      |                 ^~
      |                 tm
islands.cpp:34:8: error: 'w' was not declared in this scope
   34 |   s.PB(w[u]);
      |        ^
islands.cpp: In function 'll dfs(int)':
islands.cpp:44:2: error: 'bio' was not declared in this scope
   44 |  bio[u] = 1;
      |  ^~~
islands.cpp:45:14: error: 'g' was not declared in this scope
   45 |  for(int x : g[u]){
      |              ^
islands.cpp:47:15: error: 'w' was not declared in this scope
   47 |   ll ch = (ll)w[x] + dfs(x);
      |               ^
islands.cpp: In function 'void solve()':
islands.cpp:75:26: error: 'to' was not declared in this scope; did you mean 'tm'?
   75 |  FOR(i, 1, n + 1) cin >> to[i] >> w[i], g[to[i]].PB(i);
      |                          ^~
      |                          tm
islands.cpp:75:35: error: 'w' was not declared in this scope
   75 |  FOR(i, 1, n + 1) cin >> to[i] >> w[i], g[to[i]].PB(i);
      |                                   ^
islands.cpp:75:41: error: 'g' was not declared in this scope
   75 |  FOR(i, 1, n + 1) cin >> to[i] >> w[i], g[to[i]].PB(i);
      |                                         ^
islands.cpp:76:23: error: 'bio' was not declared in this scope
   76 |  FOR(i, 1, n + 1) if(!bio[i]) ret = 0, resi(i), ans += ret;
      |                       ^~~