Submission #777906

# Submission time Handle Problem Language Result Execution time Memory
777906 2023-07-09T22:12:45 Z teokakabadze Dreaming (IOI13_dreaming) C++17
0 / 100
30 ms 14036 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
#define n 200005
#define pb push_back
#define f first
#define s second
#define pii pair<int, int>

int mn, dp[n], b[n], d[n], mx;
bool f[n];
vector<pii> v[n];

void dfs(int u, int p)
{
    f[u] = 1;
    for(auto x : v[u])
    if(x.f != p)
    {
        dfs(x.f, u);
        if(dp[x.f] + x.s >= dp[u])
        {
            d[u] = dp[u];
            b[u] = x.f;
            dp[u] = dp[x.f] + x.s;
        }
        else d[u] = max(d[u], dp[x.f] + x.s);
    }
    mx = max(mx, d[u] + dp[u]);
}
void dfs1(int u, int p, int k)
{
    if(k >= dp[u]) b[u] = -1, dp[u] = k;
    mn = min(mn, dp[u]);
    for(auto x : v[u])
    if(x.f != p)
    {
        if(b[u] == x.f) dfs1(x.f, u, max(d[u], k) + x.s);
        else dfs1(x.f, u, dp[u] + x.s);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    int i, ans;
    vector<int> c;
    for(i = 0; i < M; i++)
    {
        v[A[i]].pb({B[i], T[i]});
        v[B[i]].pb({A[i], T[i]});
    }
    for(i = 0; i < N; i++)
    if(!f[i])
    {
        mx = 0;
        dfs(i, -1);
        mn = dp[i];
        ans = max(ans, mx);
        dfs1(i, -1, 0);
        //cout << i << ' ' << mn << '\n';
        c.pb(mn);
        //cout << i << ' ' << mn << '\n';
    }
    sort(c.rbegin(), c.rend());
    if(c.size() == 1) return max(ans, c[0]);
    if(c.size() == 2) return max(ans, L + c[0] + c[1]);
    return max(max(ans, c[0] + c[1] + L), 2 * L + c[1] + c[2]);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:45:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     int i, ans;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 14036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 14036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 8804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 14036 KB Output isn't correct
2 Halted 0 ms 0 KB -