답안 #856837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856837 2023-10-04T17:15:56 Z hariaakas646 꿈 (IOI13_dreaming) C++17
18 / 100
28 ms 11096 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 = 2e9;

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]+e.s >= ma) {
                sma = ma;
                sid = mid;
                ma = dp1[e.f]+e.s;
                mid = e.f;
            }
            else if(dp1[e.f]+e.s > sma) {
                sma = dp1[e.f]+e.s;
                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);
    dp1 = dp2 = vi(n+1);
    frange(i, m) {
        graph[A[i]+1].pb(mp(B[i]+1, T[i]));
        graph[B[i]+1].pb(mp(A[i]+1, T[i]));
    }
    int ma = -l;
    int sma = -2*l;
    int thma = -2*l;
    forr(i, 1, n+1) {
        if(!vis[i]) {
            mv = 2e9;
            dfs(i);
            dfs2(i, 0, 0);
            if(mv >= ma) {
                thma = sma;
                sma = ma;
                ma = mv;
            }
            else if(mv >= sma) {
                thma = sma;
                sma = mv;
            }
            else thma = max(thma, mv);
        }
    }
    return max(thma + sma + 2*l, 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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 11096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 11096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5720 KB Output is correct
2 Correct 12 ms 5724 KB Output is correct
3 Correct 12 ms 5980 KB Output is correct
4 Correct 15 ms 6096 KB Output is correct
5 Correct 12 ms 5980 KB Output is correct
6 Correct 13 ms 6296 KB Output is correct
7 Correct 13 ms 6236 KB Output is correct
8 Correct 12 ms 5976 KB Output is correct
9 Correct 11 ms 5988 KB Output is correct
10 Correct 12 ms 6236 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 3424 KB Output is correct
13 Correct 3 ms 3624 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 3 ms 3512 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 3 ms 3672 KB Output is correct
19 Correct 2 ms 3416 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 4 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 11096 KB Output isn't correct
2 Halted 0 ms 0 KB -