Submission #520211

# Submission time Handle Problem Language Result Execution time Memory
520211 2022-01-28T20:44:42 Z sofapuden Islands (IOI08_islands) C++14
27 / 100
1036 ms 131076 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mx = 0, bes = 0;
vector<vector<array<ll,2>>> gr;
vector<int> vis;

void dfs(int x, set<int> &s, ll dis){
    vis[x] = 1;
    s.insert(x);
    if(dis > mx){
        mx = dis;
        bes = x;
    }
    for(auto y : gr[x]){
        if(!s.count(y[0]))dfs(y[0],s,dis+y[1]);
    }
    s.erase(x);
}

int main()
{
    int n; cin >> n;
    gr.resize(n);
    vis.resize(n,0);
    for(int i = 0; i < n; ++i){
        ll a, b; cin >> a >> b;
        a--;
        gr[i].push_back({a,b});
        gr[a].push_back({i,b});
    }
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        if(!vis[i]){
            mx = 0;
            set<int> s;
            dfs(i,s,0);
            dfs(bes,s,0);
            dfs(bes,s,0);
            ans+=mx;
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 2 ms 332 KB Output isn't correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 1684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 157 ms 6452 KB Output is correct
2 Incorrect 183 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 440 ms 18048 KB Output is correct
2 Correct 591 ms 25784 KB Output is correct
3 Incorrect 682 ms 36956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 640 ms 33076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 830 ms 74532 KB Output is correct
2 Runtime error 989 ms 131076 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1036 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -