답안 #1037282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037282 2024-07-28T12:40:00 Z Ausp3x 꿈 (IOI13_dreaming) C++17
0 / 100
54 ms 13652 KB
// 人外有人,天外有天
// author: Ausp3x

#pragma GCC optimize("O1, O2, O3, Ofast, unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "dreaming.h"
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
// #define DEBUG
typedef long long    lng;

int const INF32 = 0x3f3f3f3f;
lng const INF64 = 0x3f3f3f3f3f3f3f3f;



int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<vector<pair<int, int>>> adjl(N);
    for (int i = 0; i < M; i++) {
        adjl[A[i]].pb({B[i], T[i]});
        adjl[B[i]].pb({A[i], T[i]});
    }

    vector<int> vst(N);
    vector<lng> W;
    for (int i = 0; i < N; i++) {
        if (vst[i])
            continue;
        vst[i] = true;

        if (adjl[i].empty()) {
            W.pb(0);
            continue;
        }

        int end1 = i;
        lng max_dis = 0;
        queue<pair<int, lng>> bfs;
        bfs.push({i, 0});
        while (!bfs.empty()) {
            auto [cur, cur_d] = bfs.front();
            bfs.pop();

            if (vst[cur] > 0)
                continue;
            vst[cur]++;
            
            if (cur_d > max_dis) {
                end1 = cur;
                max_dis = cur_d;
            }

            for (auto [nxt, d] : adjl[cur]) {
                if (!vst[nxt])
                    bfs.push({nxt, cur_d + d});
            } 
        }

        map<int, pair<lng, lng>> dis_from_diameter_ends;

        int end2 = end1; 
        max_dis = 0;
        bfs.push({end1, 0});
        while (!bfs.empty()) {
            auto [cur, cur_d] = bfs.front();
            bfs.pop();

            if (vst[cur] > 1)
                continue;
            vst[cur]++;
            
            if (cur_d > max_dis) {
                end2 = cur;
                max_dis = cur_d;
            }
            dis_from_diameter_ends[cur].fi = cur_d;

            for (auto [nxt, d] : adjl[cur]) {
                if (!vst[nxt])
                    bfs.push({nxt, cur_d + d});
            }
        }

        bfs.push({end2, 0});
        while (!bfs.empty()) {
            auto [cur, cur_d] = bfs.front();
            bfs.pop();

            if (vst[cur] > 2)
                continue;
            vst[cur]++;

            dis_from_diameter_ends[cur].se = cur_d;

            for (auto [nxt, d] : adjl[cur]) {
                if (!vst[nxt])
                    bfs.push({nxt, cur_d + d});
            }
        }

        lng w = INF64;
        for (auto [k, v] : dis_from_diameter_ends)
            w = min(w, max(v.fi, v.se));

        W.pb(w);
    }

    sort(W.begin(), W.end(), greater<lng>());
    
    if (W.size() == 1) {
        return W[0];
    }

    if (W.size() == 2) {
        return W[0] + W[1] + L;
    }
    
    return max(W[0] + W[1] + L, W[1] + W[2] + 2 * L);
}

#ifdef DEBUG
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    cin >> t;
    while (t--) {
        int N, M, L;
        cin >> N >> M >> L;
        int A[M], B[M], T[M];
        for (int i = 0; i < M; i++)
            cin >> A[i] >> B[i] >> T[i];
        
        cout << travelTime(N, M, L, A, B, T) << endl;
    }

    return 0;
}
#endif

Compilation message

dreaming.cpp:4:55: warning: bad option '-f O2' to pragma 'optimize' [-Wpragmas]
    4 | #pragma GCC optimize("O1, O2, O3, Ofast, unroll-loops")
      |                                                       ^
dreaming.cpp:4:55: warning: bad option '-f O3' to pragma 'optimize' [-Wpragmas]
dreaming.cpp:4:55: warning: bad option '-f Ofast' to pragma 'optimize' [-Wpragmas]
dreaming.cpp:4:55: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
In file included from dreaming.cpp:7:
dreaming.h:8:62: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
    8 | int travelTime(int N, int M, int L, int A[], int B[], int T[]);
      |                                                              ^
dreaming.h:8:62: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
dreaming.h:8:62: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
dreaming.h:8:62: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
dreaming.h:8:62: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
dreaming.h:8:62: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
dreaming.h:8:62: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
dreaming.h:8:62: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
dreaming.cpp:22:62: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
   22 | int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
      |                                                              ^
dreaming.cpp:22:62: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
dreaming.cpp:22:62: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
dreaming.cpp:22:62: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 6216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -