# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
91712 |
2018-12-29T12:21:23 Z |
easrui |
Islands (IOI08_islands) |
C++14 |
|
2000 ms |
132096 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
struct Edge{
int i,x;
long long d;
Edge(){};
Edge(int a, int b, long long c){i=a;x=b;d=c;};
};
int N;
long long D[MAX],Len,Ans;
bool vE[MAX],vN[MAX],isL[MAX];
vector<Edge> I[MAX];
stack<int> L;
vector<int> Lp;
void DFS(int i)
{
if(vN[i]){
Lp.push_back(i);
isL[i] = true;
while(L.top()!=i){
Lp.push_back(L.top());
isL[L.top()] = true;
L.pop();
}
return;
}
vN[i] = true;
L.push(i);
for(auto it : I[i]){
if(vE[it.i]) continue;
vE[it.i] = true;
DFS(it.x);
}
if(!L.empty()) L.pop();
}
void getD(int i, int x, long long d, int r)
{
if(isL[x]) return;
for(auto it : I[x]){
if(it.x==r) continue;
getD(i,it.x,it.d+d,x);
}
D[i] = max(D[i],d);
}
void getL(int i, int x, long long d, int r)
{
if(x==i) return;
if(!isL[x]) return;
for(auto it : I[x]){
if(it.x==r) continue;
getL(i,it.x,it.d+d,x);
}
Len = max(Len,d+D[x]+D[i]);
}
int main()
{
cin >> N;
for(int i=1; i<=N; i++){
int x;
long long d;
cin >> x >> d;
I[i].push_back(Edge(i,x,d));
I[x].push_back(Edge(i,i,d));
}
for(int j=1; j<=N; j++){
if(vN[j]) continue;
Lp.clear();
Len = 0;
DFS(j);
for(int i=0; i<Lp.size(); i++){
int x = Lp[i];
for(auto it : I[x]) getD(x,it.x,it.d,x);
}
for(int i=0; i<Lp.size(); i++){
int x = Lp[i];
for(auto it : I[x]) getL(x,it.x,it.d,x);
}
Ans += Len;
}
cout << Ans;
}
Compilation message
islands.cpp: In function 'int main()':
islands.cpp:75:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<Lp.size(); i++){
~^~~~~~~~~~
islands.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<Lp.size(); i++){
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Incorrect |
23 ms |
23800 KB |
Output isn't correct |
3 |
Correct |
28 ms |
23928 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
19 ms |
23800 KB |
Output is correct |
6 |
Correct |
19 ms |
23800 KB |
Output is correct |
7 |
Correct |
23 ms |
23796 KB |
Output is correct |
8 |
Correct |
23 ms |
23800 KB |
Output is correct |
9 |
Correct |
23 ms |
23852 KB |
Output is correct |
10 |
Incorrect |
22 ms |
23804 KB |
Output isn't correct |
11 |
Correct |
23 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
23976 KB |
Output is correct |
2 |
Correct |
24 ms |
24088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
24000 KB |
Output is correct |
2 |
Correct |
506 ms |
24360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1190 ms |
24952 KB |
Output is correct |
2 |
Execution timed out |
2060 ms |
27896 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2066 ms |
28772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
37984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2079 ms |
45508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
851 ms |
72732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
942 ms |
132096 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |