Submission #814803

# Submission time Handle Problem Language Result Execution time Memory
814803 2023-08-08T10:05:09 Z Magikarp4000 Dreaming (IOI13_dreaming) C++17
18 / 100
46 ms 16248 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
#define int long long

const int MAXN = 1e5+5;
int n,m,l;
vector<PII> v[MAXN];
int dp[MAXN], dp1[MAXN], dp2[MAXN];
bool z[MAXN];
vector<int> vis;

void dfs1(int s, int pa) {
    z[s] = 1;
    vis.PB(s);
    int idx = -1;
    FORX(u,v[s]) {
        if (u.F == pa) continue;
        dfs1(u.F,s);
        if (dp[u.F]+u.S > dp[s]) {
            dp[s] = dp[u.F]+u.S;
            idx = u.F;
        }
    }
    FORX(u,v[s]) if (u.F != idx) dp1[s] = max(dp1[s], dp[u.F]+u.S);
}

void dfs2(int s, int pa) {
    FORX(u,v[s]) {
        if (u.F == pa) continue;
        int c = dp[u.F]+u.S == dp[s] ? dp1[s] : dp[s];
        dp2[u.F] = max(dp2[s],c)+u.S;
        dfs2(u.F,s);
    }
}

int32_t travelTime(int32_t N, int32_t M, int32_t L, int32_t A[], int32_t B[], int32_t T[]) {
    n = N, m = M, l = L;
    FOR(i,0,m) v[A[i]].PB({B[i],T[i]}), v[B[i]].PB({A[i],T[i]});
    vector<int> vals;
    FOR(i,0,n) {
        if (z[i]) continue;
        z[i] = 1;
        vis.clear();
        dfs1(i,-1);
        dfs2(i,-1);
        int ans = LLINF;
        FORX(u,vis) ans = min(ans, max(dp[u], dp2[u]));
        vals.PB(ans);
    }
    sort(ALL(vals), greater<int>());
    if (vals.size() == 1) return vals[0];
    if (vals.size() == 2) return vals[0]+vals[1]+L;
    return max(vals[0]+vals[1]+L, vals[1]+vals[2]+2*L);
}
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 16248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 16248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 8308 KB Output is correct
2 Correct 16 ms 8364 KB Output is correct
3 Correct 16 ms 8244 KB Output is correct
4 Correct 24 ms 8236 KB Output is correct
5 Correct 21 ms 8292 KB Output is correct
6 Correct 20 ms 9064 KB Output is correct
7 Correct 26 ms 8536 KB Output is correct
8 Correct 19 ms 8148 KB Output is correct
9 Correct 22 ms 8056 KB Output is correct
10 Correct 22 ms 8436 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 5 ms 5436 KB Output is correct
13 Correct 5 ms 5736 KB Output is correct
14 Correct 5 ms 5324 KB Output is correct
15 Correct 6 ms 5404 KB Output is correct
16 Correct 6 ms 5088 KB Output is correct
17 Correct 5 ms 4300 KB Output is correct
18 Correct 5 ms 5708 KB Output is correct
19 Correct 5 ms 5196 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 10 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 16248 KB Output isn't correct
2 Halted 0 ms 0 KB -