Submission #633470

# Submission time Handle Problem Language Result Execution time Memory
633470 2022-08-22T14:09:44 Z ghostwriter Dreaming (IOI13_dreaming) C++14
18 / 100
44 ms 13184 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.c"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Practising for VOI23 gold medal
*/
const int oo = 1e9;
const int N = 1e5 + 1;
int n, m, l, c[N], d[N];
vpi adj[N];
void dfs(int u, int p) {
    EACH(j, adj[u]) {
        int v = j.st, w = j.nd;
        if (v == p) continue;
        dfs(v, u);
        d[u] = max(d[u], d[v] + w);
    }
}
void dfs1(int u, int p, int dp, int &rs) {
    c[u] = 1;
    rs = min(rs, max(d[u], dp));
    int Max1 = 0, Max2 = 0;
    EACH(j, adj[u]) {
        int v = j.st, w = j.nd;
        if (v == p) continue;
        if (Max1 < d[v] + w) {
            Max2 = Max1;
            Max1 = d[v] + w;
        }
        else Max2 = max(Max2, d[v] + w);
    }
    EACH(j, adj[u]) {
        int v = j.st, w = j.nd;
        if (v == p) continue;
        int Max = (d[v] + w == Max1? Max2 : Max1);
        dfs1(v, u, max(dp, Max) + w, rs);
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N;
    m = M;
    l = L;
    FOR(i, 0, m - 1) {
        int a = A[i], b = B[i], t = T[i];
        ++a;
        ++b;
        adj[a].pb({b, t});
        adj[b].pb({a, t});
    }
    vi a;
    FOR(i, 1, N) {
        if (c[i]) continue;
        int rs = oo;
        dfs(i, 0);
        dfs1(i, 0, 0, rs);
        a.pb(rs);
    }
    int rs = 0;
    sort(all(a));
    rs = max(rs, a.back());
    if (sz(a) > 1) rs = max(rs, a[sz(a) - 1] + a[sz(a) - 2] + l);
    if (sz(a) > 2) rs = max(rs, a[sz(a) - 2] + a[sz(a) - 3] + 2 * l);
    return rs;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:28:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   28 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
dreaming.cpp:43:5: note: in expansion of macro 'EACH'
   43 |     EACH(j, adj[u]) {
      |     ^~~~
dreaming.cpp: In function 'void dfs1(int, int, int, int&)':
dreaming.cpp:28:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   28 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
dreaming.cpp:54:5: note: in expansion of macro 'EACH'
   54 |     EACH(j, adj[u]) {
      |     ^~~~
dreaming.cpp:28:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   28 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
dreaming.cpp:63:5: note: in expansion of macro 'EACH'
   63 |     EACH(j, adj[u]) {
      |     ^~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
dreaming.cpp:74:5: note: in expansion of macro 'FOR'
   74 |     FOR(i, 0, m - 1) {
      |     ^~~
dreaming.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
dreaming.cpp:82:5: note: in expansion of macro 'FOR'
   82 |     FOR(i, 1, N) {
      |     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 13184 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 44 ms 13184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 6488 KB Output is correct
2 Correct 25 ms 6512 KB Output is correct
3 Correct 32 ms 6472 KB Output is correct
4 Correct 19 ms 6408 KB Output is correct
5 Correct 17 ms 6500 KB Output is correct
6 Correct 19 ms 7000 KB Output is correct
7 Correct 18 ms 6652 KB Output is correct
8 Correct 18 ms 6360 KB Output is correct
9 Correct 22 ms 6352 KB Output is correct
10 Correct 22 ms 6660 KB Output is correct
11 Correct 1 ms 2668 KB Output is correct
12 Correct 5 ms 3948 KB Output is correct
13 Correct 5 ms 3956 KB Output is correct
14 Correct 5 ms 3920 KB Output is correct
15 Correct 5 ms 3920 KB Output is correct
16 Correct 4 ms 3920 KB Output is correct
17 Correct 5 ms 3664 KB Output is correct
18 Correct 5 ms 3956 KB Output is correct
19 Correct 5 ms 3944 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2672 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 5 ms 3944 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 44 ms 13184 KB Output isn't correct
2 Halted 0 ms 0 KB -