Submission #814824

# Submission time Handle Problem Language Result Execution time Memory
814824 2023-08-08T10:18:22 Z Magikarp4000 Dreaming (IOI13_dreaming) C++17
18 / 100
52 ms 15412 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 && u.F != pa) 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]*1LL}), v[B[i]].PB({A[i],T[i]*1LL});
    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 52 ms 15412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 15412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7568 KB Output is correct
2 Correct 25 ms 7544 KB Output is correct
3 Correct 16 ms 7484 KB Output is correct
4 Correct 23 ms 7488 KB Output is correct
5 Correct 23 ms 7504 KB Output is correct
6 Correct 26 ms 8268 KB Output is correct
7 Correct 23 ms 7780 KB Output is correct
8 Correct 15 ms 7508 KB Output is correct
9 Correct 15 ms 7424 KB Output is correct
10 Correct 15 ms 7756 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 4 ms 4812 KB Output is correct
13 Correct 5 ms 5068 KB Output is correct
14 Correct 5 ms 4812 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 5 ms 4704 KB Output is correct
17 Correct 6 ms 4172 KB Output is correct
18 Correct 5 ms 5068 KB Output is correct
19 Correct 5 ms 4684 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2664 KB Output is correct
23 Correct 5 ms 4748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 15412 KB Output isn't correct
2 Halted 0 ms 0 KB -