답안 #881817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881817 2023-12-02T03:11:28 Z _KuroNeko_ 꿈 (IOI13_dreaming) C++17
0 / 100
32 ms 14676 KB
#include<bits/stdc++.h>
#include "dreaming.h"
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vdb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<int> si;
typedef set<long long> sl;
typedef set<double> sdb;
typedef set<string> ss;
typedef set<char> sc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ftb(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define ft(i, a, b) for (int i = a, _b = b; i < _b; ++i)
#define fgb(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define fg(i, a, b) for (int i = a, _b = b; i > _b; --i)
#define endl "\n"
const int N = 1e5;
vector<pii> adj[N + 1];
int color[N + 1];
ll up[N + 1];
ll down[N + 1];
vl ans(N + 1, 0);
void dfsDown(int node) {
    for (pii it : adj[node]) {
        if (color[it.first] == 0) {
            color[it.first] = color[node];
            dfsDown(it.first);
            down[node] = max(down[node], down[it.first] + it.second);
        }
    }
}
void dfsUp(int node, int parent) {
    ll mx1 = -1, mx2 = -1;
    for (pii it : adj[node]) {
        if (it.first != parent) {
            if (down[it.first] + it.second > mx1) {
                mx2 = mx1;
                mx1 = down[it.first] + it.second;
            }
            else {
                mx2 = max(mx2, down[it.first] + it.second);
            }
        }
    }
    for (pii it : adj[node]) {
        if (it.first != parent) {
            up[it.first] = up[node] + it.second;
            if (down[it.first] + it.second != mx1) {
                up[it.first] = max(up[it.first], mx1 + it.second);
            }
            else {
                up[it.first] = max(up[it.first], mx2 + it.second);
            }
            dfsUp(it.first, node);
        }
    }
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    ft(i, 0, m) {
        adj[a[i]].push_back({ b[i],t[i] });
        adj[b[i]].push_back({ a[i],t[i] });
    }
    int num = 1;
    ft(i, 0, n) {
        if (color[i] == 0) {
            color[i] = num++;
            dfsDown(i);
            dfsUp(i, 0);
        }
    }
    ft(i, 0, n) {
        ans[color[i]] = max(ans[color[i]], down[i] + up[i]);
    }
    vl temp;
    ft(i, 1, num) {
        temp.push_back(ans[num]);
    }
    sort(temp.rbegin(), temp.rend());
    if (temp.size() == 1) {
        return temp[0];
    }
    if (temp.size() == 2) {
        return temp[0] + temp[1] + 2;
    }
    return max(temp[0] + temp[1] + 2, temp[1] + temp[2] + 4);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 14676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 14676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 9440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 14676 KB Output isn't correct
2 Halted 0 ms 0 KB -