# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
171668 | 2019-12-29T21:01:27 Z | DavidDamian | Islands (IOI08_islands) | C++11 | 2000 ms | 131076 KB |
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int n; struct edge{ int from,to; ll w; }; vector<edge> adjList[1000006]; int color[1000006]; int p[1000006]; int weight[1000006]; vector<edge> cycle; void dfsVisit(int u) { color[u]=1; for(edge e: adjList[u]){ int v=e.to; if(v==p[u] && e.w==weight[u]) continue; if(color[v]==0){ p[v]=u; weight[v]=e.w; dfsVisit(v); } else if(color[v]==1){ //Cycle edge x=e; swap(x.from,x.to); cycle.push_back(x); swap(x.from,x.to); while(x.from!=v){ x.to=p[x.from]; x.w=weight[x.from]; cycle.push_back(x); x.from=x.to; } } } color[u]=-1; } queue<int> Q; ll d[1000006]; int c=1; ll diameter(int r) { color[r]=c; d[r]=0; Q.push(r); ll maximum=0; int node=r; while(Q.size()){ int u=Q.front(); Q.pop(); for(edge e: adjList[u]){ int v=e.to; if(v==0) continue; if(color[v]!=c){ color[v]=c; d[v]=d[u]+e.w; if(d[v]>maximum && v!=0){ maximum=d[v]; node=v; } Q.push(v); } } } color[node]=++c; d[node]=0; maximum=0; Q.push(node); while(Q.size()){ int u=Q.front(); Q.pop(); for(edge e: adjList[u]){ int v=e.to; if(v==0) continue; if(color[v]!=c){ color[v]=c; d[v]=d[u]+e.w; if(d[v]>maximum){ maximum=d[v]; node=v; } Q.push(v); } } } ll ans=d[node]; return ans; } ll total=0; ll maxPath(int root) { ll maximum=0; for(edge e: cycle){ int u=e.from,v=e.to; int id1=0,id2=0; for(int i=0;i<adjList[u].size();i++){ if(adjList[u][i].to==v && adjList[u][i].w==e.w){ id1=i; adjList[u][i].to=0; break; } } for(int i=0;i<adjList[v].size();i++){ if(adjList[v][i].to==u && adjList[v][i].w==e.w){ id2=i; adjList[v][i].to=0; break; } } ++c; maximum=max(maximum,diameter(root)); adjList[u][id1].to=v; adjList[v][id2].to=u; } return maximum; } void dfs() { for(int i=1;i<=n;i++){ if(color[i]==0){ dfsVisit(i); total+=maxPath(i); cycle.clear(); } } } int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ int a; ll b; cin>>a>>b; edge e; e.from=i; e.to=a; e.w=b; adjList[e.from].push_back(e); swap(e.from,e.to); adjList[e.from].push_back(e); } dfs(); cout<<total<<'\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 23928 KB | Output isn't correct |
2 | Correct | 23 ms | 23928 KB | Output is correct |
3 | Correct | 29 ms | 23928 KB | Output is correct |
4 | Incorrect | 24 ms | 23928 KB | Output isn't correct |
5 | Correct | 23 ms | 23928 KB | Output is correct |
6 | Incorrect | 23 ms | 23928 KB | Output isn't correct |
7 | Incorrect | 23 ms | 23800 KB | Output isn't correct |
8 | Correct | 23 ms | 23928 KB | Output is correct |
9 | Incorrect | 23 ms | 23928 KB | Output isn't correct |
10 | Correct | 23 ms | 23928 KB | Output is correct |
11 | Incorrect | 24 ms | 23928 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 23928 KB | Output is correct |
2 | Correct | 24 ms | 24056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 23928 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1781 ms | 25276 KB | Output is correct |
2 | Execution timed out | 2073 ms | 28020 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2050 ms | 29428 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2065 ms | 39924 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2057 ms | 46068 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 468 ms | 94476 KB | Output is correct |
2 | Runtime error | 730 ms | 131076 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 485 ms | 131076 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |