# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89902 | 2018-12-19T00:40:06 Z | psmao | Islands (IOI08_islands) | C++14 | 2 ms | 716 KB |
#include <bits/stdc++.h> using namespace std; #define fo(i,s,t) for(int i = s; i <= t; ++ i) #define fd(i,s,t) for(int i = s; i >= t; -- i) #define bf(i,s) for(int i = head[s]; i; i = e[i].next) #define mp make_pair #define fi first #define se second #define pii pair<int,int> #define pb push_back #define VI vector<int> #define sf scanf #define pf printf #define fp freopen #define SZ(x) ((int)(x).size()) #ifdef MPS #define D(x...) printf(x) #else #define D(x...) #endif typedef long long ll; typedef double db; typedef unsigned long long ull; const int inf = 1<<30; const ll INF = 1ll<<60; const db Inf = 1e20; const db eps = 1e-9; void gmax(int &a,int b){a = (a > b ? a : b);} void gmin(int &a,int b){a = (a < b ? a : b);} const int maxn = 1000050; int n, deg[maxn]; ll Ans, dm[maxn]; pii adj[maxn]; pair<ll,ll> dp[maxn]; ll solve(int x) { deque<pair<ll,int> > Q; vector<pair<int,ll> > V; V.emplace_back(mp(0,0ll)); int sz = 0; ll ret = 0; while(deg[x]) { -- deg[x]; V.pb(mp(x, adj[x].se)); dm[x] = max(dm[x], dp[x].fi + dp[x].se); ret = max(ret, dm[x]); x = adj[x].fi; ++ sz; } fo(i,1,sz) V[i].se += V[i-1].se; fo(i,2,sz) { while(SZ(Q) && Q.back().fi < V[i-1].se + dp[V[i].fi].fi) Q.pop_back(); Q.emplace_back(mp(V[i-1].se + dp[V[i].fi].fi, V[i].fi)); } ret = max(ret, dp[V[1].fi].fi + Q.front().fi); fo(i,1,sz-1) { if(Q.front().se == V[i+1].fi) Q.pop_front(); while(SZ(Q) && Q.back().fi < V[sz].se + V[i-1].se + dp[V[i].fi].fi) Q.pop_back(); Q.emplace_back(mp(V[sz].se+V[i-1].se+dp[V[i].fi].fi, V[i].fi)); ret = max(ret, Q.front().fi + dp[V[i+1].fi].fi - V[i].se); } return ret; } int main() { fp("isl.in","r",stdin); fp("isl.out","w",stdout); sf("%d",&n); fo(i,1,n) {int u, v; sf("%d%d",&u,&v); deg[u] ++; adj[i] = (mp(u, v));} queue<int> Q; fo(i,1,n) if(!deg[i]) Q.push(i); while(!Q.empty()) { int h = Q.front(); Q.pop(); pii p = adj[h]; dm[h] = max(dm[h], dp[h].fi + dp[h].se); dm[p.fi] = max(dm[p.fi], dm[h]); ll x = dp[h].fi + p.se; if(x > dp[p.fi].fi) swap(x, dp[p.fi].fi); if(x > dp[p.fi].se) swap(x, dp[p.fi].se); if(!(--deg[p.fi])) Q.push(p.fi); } fo(i,1,n) if(deg[i]) Ans += solve(i); cout << Ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Output isn't correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Incorrect | 2 ms | 484 KB | Output isn't correct |
4 | Incorrect | 2 ms | 484 KB | Output isn't correct |
5 | Incorrect | 2 ms | 484 KB | Output isn't correct |
6 | Incorrect | 2 ms | 600 KB | Output isn't correct |
7 | Incorrect | 2 ms | 668 KB | Output isn't correct |
8 | Incorrect | 2 ms | 676 KB | Output isn't correct |
9 | Incorrect | 2 ms | 716 KB | Output isn't correct |
10 | Incorrect | 2 ms | 716 KB | Output isn't correct |
11 | Incorrect | 2 ms | 716 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |