답안 #288270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288270 2020-09-01T11:12:59 Z BeanZ 꿈 (IOI13_dreaming) C++14
18 / 100
78 ms 14584 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll dp[N], res, vis[N], vis2[N], diameter;
vector<pair<ll, ll>> node[N];
void dfsFirst(ll u){
        vis[u] = 1;
        for (auto j : node[u]){
                if (vis[j.first]) continue;
                dfsFirst(j.first);
                dp[u] = max(dp[u], dp[j.first] + j.second);
        }
}
void reroot(ll u, ll v){
        dp[u] = 0;
        for (auto j : node[u]){
                if (j.first == v) continue;
                dp[u] = max(dp[u], dp[j.first] + j.second);
        }
        dp[v] = 0;
        for (auto j : node[v]){
                dp[v] = max(dp[v], dp[j.first] + j.second);
        }
        if (res >= dp[v]){
                res = min(res, dp[v]);
                vector<ll> mem;
                for (auto j : node[v]){
                        mem.push_back(dp[j.first] + j.second);
                }
                ll ok = 0;
                if (mem.size()){
                        sort(mem.begin(), mem.end());
                        for (int i = mem.size() - 1; i >= max((ll)mem.size() - 2, 0ll); i--){
                                ok += mem[i];
                        }
                }
                diameter = max(diameter, ok);
        }
}
void dfs(ll u, ll p){
        for (auto j : node[u]){
                if (j.first == p) continue;
                reroot(u, j.first);
                dfs(j.first, u);
                reroot(j.first, u);
        }
}
void fuck(ll u){
        vector<ll> mem;
        for (auto j : node[u]){
                mem.push_back(dp[j.first] + j.second);
        }
        diameter = 0;
        if (mem.size()){
                sort(mem.begin(), mem.end());
                for (int i = mem.size() - 1; i >= max((ll)mem.size() - 2, 0ll); i--){
                        diameter += mem[i];
                }
        }
}
int travelTime(int N, int M, int L, int A[],int B[],int T[]){
        for (int i = 1; i <= M; i++){
                node[A[i - 1]].push_back({B[i - 1], T[i - 1]});
                node[B[i - 1]].push_back({A[i - 1], T[i - 1]});
        }
        priority_queue<ll> pq;
        ll ans = 0;
        for (int i = 1; i <= N; i++){
                if (!vis[i]){
                        diameter = 0;
                        dfsFirst(i);
                        res = dp[i];
                        fuck(i);
                        dfs(i, i);
                        ans = max(ans, diameter);
                        pq.push(res);
                }
        }
        ll root = pq.top();
        pq.pop();
        ll mx = -1e18;
        while (pq.size()){
                ans = max(ans, pq.top() + 2 * L + mx);
                ans = max(ans, pq.top() + L + root);
                mx = max(mx, pq.top());
                pq.pop();
        }
        return ans;
}
/*
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("VietCT.INP", "r")){
                freopen("VietCT.INP", "r", stdin);
                freopen("VietCT.OUT", "w", stdout);
        }
        int n, m, l;
        cin >> n >> m >> l;
        vector<int> a, b, t;
        for (int i = 1; i <= m; i++){
                int u, v, c;
                cin >> u >> v >> c;
                a.push_back(u + 1);
                b.push_back(v + 1);
                t.push_back(c);
        }
        cout << travelTime(n, m, l, a, b, t);
}
*/
/*
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13944 KB Output is correct
2 Correct 78 ms 14584 KB Output is correct
3 Correct 42 ms 9848 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 9 ms 3840 KB Output is correct
6 Correct 17 ms 5504 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13944 KB Output is correct
2 Correct 78 ms 14584 KB Output is correct
3 Correct 42 ms 9848 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 9 ms 3840 KB Output is correct
6 Correct 17 ms 5504 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13944 KB Output is correct
2 Correct 78 ms 14584 KB Output is correct
3 Correct 42 ms 9848 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 9 ms 3840 KB Output is correct
6 Correct 17 ms 5504 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 7600 KB Output is correct
2 Correct 37 ms 7544 KB Output is correct
3 Correct 40 ms 7584 KB Output is correct
4 Correct 37 ms 7544 KB Output is correct
5 Correct 37 ms 7552 KB Output is correct
6 Correct 41 ms 8308 KB Output is correct
7 Correct 41 ms 7800 KB Output is correct
8 Correct 38 ms 7416 KB Output is correct
9 Correct 34 ms 7412 KB Output is correct
10 Correct 38 ms 7668 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 11 ms 5368 KB Output is correct
13 Correct 11 ms 5496 KB Output is correct
14 Correct 10 ms 5240 KB Output is correct
15 Correct 10 ms 5368 KB Output is correct
16 Correct 10 ms 5240 KB Output is correct
17 Correct 10 ms 4728 KB Output is correct
18 Correct 11 ms 5496 KB Output is correct
19 Correct 10 ms 5240 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2816 KB Output is correct
23 Correct 10 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13944 KB Output is correct
2 Correct 78 ms 14584 KB Output is correct
3 Correct 42 ms 9848 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 9 ms 3840 KB Output is correct
6 Correct 17 ms 5504 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13944 KB Output is correct
2 Correct 78 ms 14584 KB Output is correct
3 Correct 42 ms 9848 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 9 ms 3840 KB Output is correct
6 Correct 17 ms 5504 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -