Submission #856817

# Submission time Handle Problem Language Result Execution time Memory
856817 2023-10-04T16:38:50 Z hariaakas646 Dreaming (IOI13_dreaming) C++17
0 / 100
28 ms 16724 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
    // freopen("disrupt.in", "r", stdin);
    // freopen("disrupt.out", "w", stdout);
}

vector<vii> graph;
vb vis;
vi dp1, dp2;

int mv = 1e9;

void dfs(int x) {
    vis[x] = true;
    for(auto e : graph[x]) {
        if(!vis[e.f]) {
            dfs(e.f);
            dp1[x] = max(dp1[x], e.s + dp1[e.f]);
        }
    }
}

void dfs2(int x, int p, int d) {
    if(p) {
        dp2[x] = max(dp2[x], dp2[p] + d);
    }
    mv = min(mv, max(dp1[x], dp2[x]));
    int ma = 0;
    int mid = 0;
    int sma = 0;
    int sid = 0;
    for(auto e : graph[x]) {
        if(e.f != p) {
            if(dp1[e.f] >= ma) {
                sma = ma;
                sid = mid;
                ma = dp1[e.f];
                mid = e.f;
            }
            else if(dp1[e.f] > sma) {
                sma = dp1[e.f];
                sid = e.f;
            }
        }
    }
    for(auto e : graph[x]) {
        if(e.f != p) {
            if(e.f == mid) {
                dp2[e.f] = max(dp2[e.f], sma + e.s);
            }
            else {
                dp2[e.f] = max(dp2[e.f], ma + e.s);
            }
            dfs2(e.f, x, e.s);
        }
    }

}

int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
    graph = vector<vii>(n+1);
    vis = vb(n+1);
    frange(i, m) {
        graph[A[i]].pb(mp(B[i], T[i]));
        graph[B[i]].pb(mp(A[i], T[i]));
    }
    int ma = -l;
    int sma = -l;
    forr(i, 1, n+1) {
        if(!vis[i]) {
            mv = 0;
            dfs(1);
            dfs2(1, 0, 0);
            if(mv >= ma) {
                sma = ma;
                ma = mv;
            }
            else sma = max(sma, mv);
        }
    }
    return ma + l + sma;

}

Compilation message

dreaming.cpp: In function 'void dfs2(int, int, int)':
dreaming.cpp:60:9: warning: variable 'sid' set but not used [-Wunused-but-set-variable]
   60 |     int sid = 0;
      |         ^~~
dreaming.cpp: In function 'void usaco()':
dreaming.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 16724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 16724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 10076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 16724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -