답안 #119892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119892 2019-06-22T14:55:24 Z dolphingarlic 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 13560 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#pragma GCC optimize("O3")
#define FOR(i, x, y) for (ll i = x; i < y; i++)
typedef long long ll;
using namespace std;

vector<pair<ll, ll>> graph[100001];
ll len, ans = -1, r[2], indx = 0, cmp[100001];
pair<ll, ll> dp[100001];
bool visited[100001];

void ff(int node, int component, int parent = -1) {
    visited[node] = true;
    cmp[node] = component;
    for (auto& i : graph[node]) {
        if (i.first == parent) continue;
        ff(i.first, component, node);
    }
}

void dfs(ll node, ll parent = -1) {
    int mx1 = 0, mx2 = 0;
    for (auto& i : graph[node]) {
        if (i.first == parent) continue;
        dfs(i.first, node);

        int e = dp[i.first].first + i.second;
        if (e > mx1) {
            mx2 = mx1;
            mx1 = e;
        } else if (e > mx2)
            mx2 = e;
    }
    dp[node] = {mx1, mx2};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    FOR(i, 0, M) {
        graph[A[i]].push_back({B[i], T[i]});
        graph[B[i]].push_back({A[i], T[i]});
    }

    FOR(i, 0, N) if (!visited[i]) ff(i, indx++);

    fill(r, r + indx, INT_MAX);
    FOR(i, 0, N) {
        dfs(i);
        r[cmp[i]] = min(r[cmp[i]], dp[i].first);
        ans = max(ans, dp[i].first + dp[i].second);
    }
    sort(r, r + indx, greater<ll>());

    return 0;
    ans = max(ans, max((indx > 2 ? r[1] + r[2] + 2 * L : 0),
                       max((indx > 1 ? r[0] + r[1] + L : 0), r[0])));
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 13560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 13560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 13560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 12048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 13560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 13560 KB Time limit exceeded
2 Halted 0 ms 0 KB -