# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59214 | 2018-07-21T07:08:15 Z | gnoor | Islands (IOI08_islands) | C++17 | 2000 ms | 132096 KB |
#include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; struct edge { int to,wgt; int id; }; vector<edge> pth[1000100]; bool visit[1000100]; bool incyc[1000100]; int cyc[2000100]; long long wgt[2000100]; long long dis[2000100]; int cn; int dfs(int x,int p) { visit[x]=true; int ret=0; bool toret=false; for (auto i:pth[x]) { if (i.id==p) continue; if (visit[i.to]) { if (toret) continue; cyc[cn]=x; wgt[cn]=i.wgt; incyc[x]=true; cn++; ret=i.to; toret=true; continue; } int res=dfs(i.to,i.id); if (toret) continue; if (res) { cyc[cn]=x; wgt[cn]=i.wgt; incyc[x]=true; cn++; if (res!=x) ret=res; else ret=0; toret=true; } } return ret; } long long dmax[1000100]; long long survey(int x,int p) { long long res=0; long long mx=0; long long smx=0; long long cur; dmax[x]=0; for (auto i:pth[x]) { if (i.id==p) continue; if (incyc[i.to]) continue; cur=i.wgt+survey(i.to,i.id); if (cur>=mx) { smx=mx; mx=cur; } else if (cur>smx) { smx=cur; } res=max(res,i.wgt+survey(i.to,i.id)); dmax[x]=max(dmax[x],dmax[i.to]); } dmax[x]=max(dmax[x],mx+smx); return res; } int main () { int n; scanf("%d",&n); int a,b; for (int i=1;i<=n;i++) { scanf("%d%d",&a,&b); pth[i].push_back(edge{a,b,i}); pth[a].push_back(edge{i,b,i}); } long long ans=0; for (int i=1;i<=n;i++) { if (visit[i]) continue; cn=1; dfs(i,0); cn--; for (int j=1;j<=cn;j++) { dis[j]=survey(cyc[j],0); dis[j+cn]=dis[j]; wgt[j+cn]=wgt[j]; cyc[j+cn]=cyc[j]; } wgt[0]=0; for (int j=1;j<=cn*2;j++) { wgt[j]+=wgt[j-1]; } deque<int> qq; qq.push_back(1); long long cur=0; for (int j=2;j<=cn*2;j++) { while (!qq.empty()&&qq.front()<=j-cn) qq.pop_front(); cur=max(cur,wgt[j]+dis[j]+dis[qq.front()]-wgt[qq.front()]); cur=max(cur,dmax[cyc[j]]); while (!qq.empty()&&dis[qq.back()]-wgt[qq.back()]<=dis[j]-wgt[j]) qq.pop_back(); qq.push_back(j); } ans+=cur; } printf("%lld\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 23800 KB | Output is correct |
2 | Correct | 39 ms | 23916 KB | Output is correct |
3 | Correct | 27 ms | 23952 KB | Output is correct |
4 | Correct | 29 ms | 24000 KB | Output is correct |
5 | Correct | 27 ms | 24000 KB | Output is correct |
6 | Correct | 25 ms | 24072 KB | Output is correct |
7 | Correct | 26 ms | 24072 KB | Output is correct |
8 | Correct | 26 ms | 24072 KB | Output is correct |
9 | Correct | 29 ms | 24072 KB | Output is correct |
10 | Correct | 27 ms | 24172 KB | Output is correct |
11 | Correct | 26 ms | 24172 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 24224 KB | Output is correct |
2 | Correct | 28 ms | 24236 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 24400 KB | Output is correct |
2 | Correct | 26 ms | 24700 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 25540 KB | Output is correct |
2 | Correct | 68 ms | 28568 KB | Output is correct |
3 | Execution timed out | 2060 ms | 28568 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 30928 KB | Output is correct |
2 | Correct | 97 ms | 34568 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 183 ms | 42104 KB | Output is correct |
2 | Execution timed out | 2063 ms | 46824 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 356 ms | 58840 KB | Output is correct |
2 | Correct | 341 ms | 93412 KB | Output is correct |
3 | Execution timed out | 2090 ms | 95712 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 544 ms | 112320 KB | Output is correct |
2 | Runtime error | 1393 ms | 132096 KB | Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2073 ms | 132096 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |