답안 #548138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548138 2022-04-12T14:11:23 Z sofapuden Islands (IOI08_islands) C++14
30 / 100
1117 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);
                ans+=mx;
            }
        }
        cout << ans << '\n';
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 1832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 277 ms 7008 KB Output is correct
2 Incorrect 291 ms 11264 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 690 ms 19032 KB Output is correct
2 Correct 983 ms 28068 KB Output is correct
3 Incorrect 1117 ms 40660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1044 ms 34280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 988 ms 90296 KB Output is correct
2 Runtime error 1027 ms 131072 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 961 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -