Submission #853164

#TimeUsernameProblemLanguageResultExecution timeMemory
853164onepunchac168Dreaming (IOI13_dreaming)C++14
100 / 100
83 ms19304 KiB
//------------------------------------\\
//   ------------------------------   \\
//  |  created by Dinh Manh Hung   |  \\
//  |      tht.onepunchac168       |  \\
//  |     THPT CHUYEN HA TINH      |  \\
//  |      HA TINH, VIET NAM       |  \\
//  |           Siuuu              |  \\
//   ------------------------------   \\
//------------------------------------\\

#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

#define            task     ""
#define       file(name)    if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define             ldb     long double
#define              pb     push_back
#define              eb     emplace_back
#define              fi     first
#define              se     second
#define           all(x)    begin(x),end(x)
#define       uniquev(v)    v.resize(unique(all(v))-v.begin())
#define       rep(i,a,b)    for (int i=a;i<=b;i++)
#define        cntbit(v)    __builtin_popcountll(v)
#define         gcd(a,b)    __gcd(a,b)
#define         lcm(a,b)    ((1LL*a*b)/__gcd(a,b))
#define          mask(x)    (1LL<<(x))
#define     readbit(x,i)    ((x>>i)&1)
#define             Yes     cout << "Yes"
#define             YES     cout << "YES"
#define              No     cout << "No"
#define              NO     cout << "NO"

typedef long long ll;
typedef pair <ll,ll> ii;
typedef pair <ll,ii> iii;
typedef pair <ii,ii> iiii;

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

const ldb PI = acos (-1);
//const ll mod=978846151;
//const ll base=29;
const ll mod=1e9+7;
const char nl = '\n';

inline int ReadInt()
{
    char co;
    for (co = getchar(); co < '0' || co > '9'; co = getchar());
    int xo = co - '0';
    for (co = getchar(); co >= '0' && co <= '9'; co = getchar())
        xo = (xo<<1) + (xo<<3) + co - '0';
    return xo;
}

void WriteInt(int xo)
{
    if (xo > 9)
        WriteInt(xo / 10);
    putchar(xo % 10 + '0');
}

// DEBUG

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


/* END OF TEMPLATE*/

// ================= Solution =================//

const int N=1e5+5;
bool fee[N];
bool feea[N];
vector <ii> vt[N];
ll dp[N];
ll dpa[N];
void dfs(int u)
{
    fee[u]=1;
    dp[u]=0;
    dpa[u]=0;
    for (auto v:vt[u])
    {
        if (fee[v.fi]==1)
        {
            continue;
        }
        dfs(v.fi);
        if (dp[v.fi]+v.se>dp[u])
        {
            dpa[u]=dp[u];
            dp[u]=dp[v.fi]+v.se;
        }
        else if (dp[v.fi]+v.se>dpa[u])
        {
            dpa[u]=dp[v.fi]+v.se;
        }
    }
}
ll res;
ll cnt[N];
ll gmax=0;
void dfsa(int u)
{
    feea[u]=1;
    res=min(res,max(cnt[u],dp[u]));
    gmax=max({gmax,cnt[u],dp[u]});
    for (auto v:vt[u])
    {
        if (feea[v.fi]==1)
        {
            continue;
        }
        cnt[v.fi]=cnt[u]+v.se;
        if (dp[v.fi]+v.se==dp[u])
        {
            cnt[v.fi]=max(cnt[v.fi],dpa[u]+v.se);
        }
        else cnt[v.fi]=max(cnt[v.fi],dp[u]+v.se);
        dfsa(v.fi);
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i=0;i<M;i++)
    {
        vt[A[i]].pb({B[i],T[i]});
        vt[B[i]].pb({A[i],T[i]});
    }
    for (int i=0;i<N;i++)
    {
        if (fee[i]==0)
        {
            dfs(i);
        }
    }
    vector <ll> tmp;
    for (int i=0;i<N;i++)
    {
        if (feea[i]==0)
        {
            res=1e18+5;
            dfsa(i);
            tmp.pb(res);
        }
    }
    sort(tmp.begin(),tmp.end(),greater <ll> ());
    if (tmp.size()==1)
    {

    }
    else if (tmp.size()==2)
    {
        gmax=max(gmax,L+tmp[0]+tmp[1]);
    }
    else
    {
        gmax=max(gmax,L+tmp[0]+tmp[1]);
        gmax=max(gmax,L+L+tmp[1]+tmp[2]);
    }
    return gmax;
}
/*
void onepunchac168();

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    file(task);
    int tests;
    tests=1;
    //cin>>tests;
    while (tests--)
    {
        onepunchac168();
    }
}

const int N=2e5+5;

void onepunchac168()
{

}
*/

// goodbye see ya

Compilation message (stderr)

dreaming.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //------------------------------------\\
      | ^
#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...