Submission #928968

# Submission time Handle Problem Language Result Execution time Memory
928968 2024-02-17T10:53:00 Z Foolestboy Dreaming (IOI13_dreaming) C++14
0 / 100
42 ms 32208 KB
#ifndef GNORT
#include "dreaming.h"
#endif // GNORT
#include <bits/stdc++.h>

#define SQR(x)    (1LL * ((x) * (x)))
#define MASK(i)   (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi        first
#define se        second
#define pb        push_back
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define sz(s)     (int)s.size()
#define prev      __prev
#define next      __next
#define left      __left
#define right     __right

#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;

using namespace std;

const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);

const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};

template<class BUI, class TRONG>
    bool minimize(BUI &x, const TRONG y){
        if(x > y){
            x = y;
            return true;
        } else return false;
    }
template<class BUI, class TRONG>
    bool maximize(BUI &x, const TRONG y){
        if(x < y){
            x = y;
            return true;
        } else return false;
    }

/* Author : Bui Nguyen Duc Trong, Luong Van Chanh High School for the gifted*/
/* Template is copied by Trong */

                           /** Losing in Provincial Contests **/
                                    /** TRYING HARDER**/
                                   /**      ORZ     **/

/* -----------------[ MAIN CODE GOES HERE ]----------------- */

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 10;

bool vis[N];
vector<pii> adj[N];
int high[N];
int cc;
vector<int> nodes[N];
int maxVal[N];
int dist[101][101];

void dfsdist(int r, int u, int p){
    for(auto [v, w] : adj[u]){
        if(v == p) continue;
        dist[r][v] = dist[r][u] + w;
        dfsdist(r, v, u);
    }
}

void dfs(int u, int p, int &x, bool take){
    vis[u] = 1;
    if(take) nodes[cc].push_back(u);
    if(high[u] > high[x]) x = u;
    for(auto [v, w] : adj[u]){
        if(v == p) continue;
        high[v] = high[u] + w;
        dfs(v, u, x, take);
    }
}

int f[N][2];

void dfs2(int u, int p, int k){
    for(auto [v, w] : adj[u]){
        if(v == p) continue;
        f[v][k] = f[u][k] + w;
        dfs2(v, u, k);
    }
}

int travelTime(int n, int m, int len, int A[], int B[], int T[]) {
    for(int i = 0; i < m; i++){
        adj[A[i]].push_back(mp(B[i], T[i]));
        adj[B[i]].push_back(mp(A[i], T[i]));
    }
    int ans = 0;
    memset(maxVal, 0x3f, sizeof maxVal);
    for(int i = 0; i < n; i++){
        if(!vis[i]){
            ++cc;
            int x = i, y = i;
            dfs(i, 0, x, 1);
            for(int u = 0; u < sz(nodes[cc]); u++) dfsdist(nodes[cc][u], nodes[cc][u], 0);
            for(int u : nodes[cc]){
                int maxDist(0);
                for(int v : nodes[cc]) maximize(maxDist, dist[u][v]);
                minimize(maxVal[cc], maxDist);
                maximize(ans, maxDist);
            }
//            for(int z : nodes[cc]) high[z] = 0;
//            dfs(x, 0, y, 0);
//            dfs2(x, 0, 0);
//            dfs2(y, 0, 1);
//            for(int z : nodes[cc]){
//                maximize(ans, f[z][0] + f[z][1]);
//                minimize(maxVal[cc], max(f[z][0], f[z][1]));
//            }
        }
    }
    multiset<int, greater<>> st;
    for(int i = 1; i <= cc; i++) st.insert(maxVal[i]);
    int h = INT_MAX;
    for(int i = 1; i <= cc; i++){
        st.erase(st.find(maxVal[i]));
        int cost = 0;
        if(sz(st) >= 1) maximize(cost, *st.begin() + len + maxVal[i]);
        if(sz(st) >= 2){
            int tmp = 0;
            auto it = st.begin();
            tmp += *(it);
            ++it;
            tmp += *(it);
            maximize(cost, 2 * len + tmp);
        }
        st.insert(maxVal[i]);
        minimize(h, cost);
    }
    maximize(ans, h);
    return ans;
}

#ifdef GNORT
void solve(){
    int n, m, len; cin >> n >> m >> len;
    int A[101], B[101], T[101];
    for(int i = 0; i < m; i++){
        cin >> A[i] >> B[i] >> T[i];
    }
    cout << travelTime(n, m, len, A, B, T) << '\n';
}
/*
2 0 3
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    const bool multitest = 0;
    int tt = 1; if(multitest) cin >> tt;

    while( tt-- ){

        solve();

    }

    return 0;
}
#endif

Compilation message

dreaming.cpp: In function 'void dfsdist(int, int, int)':
dreaming.cpp:78:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |     for(auto [v, w] : adj[u]){
      |              ^
dreaming.cpp: In function 'void dfs(int, int, int&, bool)':
dreaming.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   89 |     for(auto [v, w] : adj[u]){
      |              ^
dreaming.cpp: In function 'void dfs2(int, int, int)':
dreaming.cpp:99:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   99 |     for(auto [v, w] : adj[u]){
      |              ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:116:24: warning: unused variable 'y' [-Wunused-variable]
  116 |             int x = i, y = i;
      |                        ^
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 32208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7668 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Incorrect 2 ms 7512 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 32208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 19544 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7668 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Incorrect 2 ms 7512 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 32208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -