답안 #417481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417481 2021-06-03T19:09:06 Z iulia13 꿈 (IOI13_dreaming) C++14
18 / 100
57 ms 13544 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int N = 1e5 + 5;
struct ura{
    int x, c;
};
vector <ura> g[N];
int maxi = 2e9, dp[N], dp2[N], dp_up[N];
int lover[N];
int viz[N];
vector <int> A;
void dfs(int nod, int dad = -1)
{
    viz[nod] = 1;
    for (auto son : g[nod])
    {
        if (son.x == dad)
            continue;
        dfs(son.x, nod);
        if (dp[nod] < dp[son.x] + son.c)
        {
            dp2[nod] = dp[nod];
            dp[nod] = dp[son.x] + son.c;
        }
        else
            dp2[nod] = max(dp2[nod], dp[son.x] + son.c);
    }
}
void dfs2(int nod, int dad = -1)
{
    for (auto son : g[nod])
    {
        if (son.x == dad)
            continue;
        int c = dp[nod];
        if (c == dp[son.x] + son.c)
            c = dp2[nod];
        dp_up[son.x] = max(dp_up[nod], c) + son.c;
        dfs2(son.x, nod);
    }
    lover[nod] = max(dp_up[nod], dp[nod]);
    maxi = min(lover[nod], maxi);
}
int travelTime(int n, int m, int l, int a[], int b[], int t[])
{
    int i, j;
    for (i = 0; i < m; i++)
    {
        g[a[i]].push_back({b[i], t[i]});
        g[b[i]].push_back({a[i], t[i]});
    }
    for (i = 0; i < n; i++)
    {
        if (viz[i])
            continue;
        maxi = 2e9;
        dfs(i);
        dfs2(i);
        A.push_back(maxi);
    }
    if (A.size() == 1)
        return A[0];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    int c = A[0] + A[1] + l;
    if (A.size() == 2)
        return c;
    else
        return max(c, A[1] + A[2] + 2 * l);
}/*
int a[N];
int b[N];
int t[N];
int main()
{
    int n, m, l, i;
    cin >> n >> m >> l;
    for (i = 0; i < m; i++)
        cin >> a[i] >> b[i] >> t[i];
    cout << travelTime(n, m, l, a, b, t);
    return 0;
}*/

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:12: warning: unused variable 'j' [-Wunused-variable]
   47 |     int i, j;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 13544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 13544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 7528 KB Output is correct
2 Correct 25 ms 7624 KB Output is correct
3 Correct 24 ms 7512 KB Output is correct
4 Correct 24 ms 7628 KB Output is correct
5 Correct 26 ms 7596 KB Output is correct
6 Correct 29 ms 8060 KB Output is correct
7 Correct 36 ms 7852 KB Output is correct
8 Correct 26 ms 7540 KB Output is correct
9 Correct 25 ms 7400 KB Output is correct
10 Correct 28 ms 7744 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 6 ms 4936 KB Output is correct
13 Correct 7 ms 5060 KB Output is correct
14 Correct 7 ms 4932 KB Output is correct
15 Correct 7 ms 4936 KB Output is correct
16 Correct 6 ms 4808 KB Output is correct
17 Correct 6 ms 4296 KB Output is correct
18 Correct 7 ms 5060 KB Output is correct
19 Correct 6 ms 4808 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 6 ms 4808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 13544 KB Output isn't correct
2 Halted 0 ms 0 KB -