Submission #548139

# Submission time Handle Problem Language Result Execution time Memory
548139 2022-04-12T14:12:24 Z sofapuden Islands (IOI08_islands) C++14
30 / 100
2000 ms 131072 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);
                dfs(bes,s,0);
                dfs(bes,s,0);
                dfs(bes,s,0);
                dfs(bes,s,0);
                dfs(bes,s,0);
                dfs(bes,s,0);
                dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
              dfs(bes,s,0);
                ans+=mx;
            }
        }
        cout << ans << '\n';
    }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Incorrect 5 ms 372 KB Output isn't correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 182 ms 1672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 768 ms 6464 KB Output is correct
2 Incorrect 710 ms 10188 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1934 ms 18088 KB Output is correct
2 Execution timed out 2083 ms 25904 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 33104 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1549 ms 74692 KB Output is correct
2 Runtime error 986 ms 131072 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 943 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -