제출 #591026

#제출 시각아이디문제언어결과실행 시간메모리
591026KrisjanisP꿈 (IOI13_dreaming)C++14
100 / 100
702 ms17796 KiB
#include "dreaming.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using ll = int;
using ii = pair<ll,ll>;
const ll MX = 100000;
vector<pair<ii,ll>> AL[MX]; // {{u,w},e}
bool visited[MX];

bool maxDepthMemVis[2*MX];
ll maxDepthMem[2*MX];
ii edge[MX*2]; // directional {from, to}
// returns the maximum depth
ll maxDepth(ll e)
{
    if(maxDepthMemVis[e])
        return maxDepthMem[e];
    ll p = edge[e].first, v = edge[e].second;
    ll res = 0;
    for(auto& z: AL[v])
    {
        ll u = z.first.first;
        ll w = z.first.second;
        ll ne = z.second;
        if(u==p) continue;
        res = max(res, maxDepth(ne)+w);
    }
    maxDepthMemVis[e] = 1;
    maxDepthMem[e] = res;
    return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(ll i=0;i<M;i++)
    {
        ll a = A[i], b=B[i], w=T[i];
        AL[a].push_back({{b,w},2*i});
        AL[b].push_back({{a,w},2*i+1});
        edge[2*i] = {a,b};
        edge[2*i+1] = {b,a};
    }
    vector<ll> ecc; // eccentricity vector
    ll res = 0;
    for(ll i=0;i<N;i++)
    {
        if(visited[i]) continue;
        vector<ll> nodes;
        queue<ll> q;
        q.push(i);
        visited[i]=1;
        nodes.push_back(i);
        while(!q.empty())
        {
            ll v = q.front(); q.pop();
            for(auto& z: AL[v])
            {
                ll u = z.first.first;
                if(visited[u]) continue;
                q.push(u);
                visited[u]=1;
                nodes.push_back(u);
            }
        }
        //cout<<"nodes: "; for(ll v: nodes) cout<<v<<" "; cout<<"\n";
        ll mnMxDepth = 1e10;
        for(ll v: nodes)
        {
            ll mxDepth = 0;
            for(auto& z: AL[v])
            {
                ll u = z.first.first;
                ll w = z.first.second;
                ll ne = z.second;
                mxDepth=max(mxDepth, maxDepth(ne)+w);
            }
            res = max(res,mxDepth);
            mnMxDepth = min(mnMxDepth, mxDepth);
        }
        ecc.push_back(mnMxDepth);
    }
    sort(ecc.begin(),ecc.end(),greater<ll>());
    //cout<<"ecc: "; for(ll x: ecc) cout<<x<<" "; cout<<"\n";
    res = max(res, ecc[0]);
    if(ecc.size()>=2) res=max(res,ecc[0]+ecc[1]+L);
    if(ecc.size()>=3) res=max(res,ecc[1]+ecc[2]+2*L);
    return res;
}

컴파일 시 표준 에러 (stderr) 메시지

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:67:24: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+10' to '2147483647' [-Woverflow]
   67 |         ll mnMxDepth = 1e10;
      |                        ^~~~
dreaming.cpp:73:20: warning: unused variable 'u' [-Wunused-variable]
   73 |                 ll u = z.first.first;
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...