제출 #1082425

#제출 시각아이디문제언어결과실행 시간메모리
1082425modwwe꿈 (IOI13_dreaming)C++17
100 / 100
48 ms14036 KiB
#include "dreaming.h"
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while(c<'0'||c>'9')
    {
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf=1e9;
const int mod2=1e9+9;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2;
int  i,s10,s12;
int kk;
int el=29;
int dist[100001],dist2[100001],dist3[100002];
ib heavy[100001];
vector<ib>v[100001];
bool b[100001];
struct gg
{
    void dfs(int x,int y)
    {
        b[x]=1;
        for(auto f:v[x])
        {
            if(f.a!=y)
            {
                dist[f.a]=dist[x]+f.b;
                dfs(f.a,x);
            }
        }
        if(dist[x]>s4)
            s3=x,s4=dist[x];
        dist[x]=0;

    }
    int get(int x)
    {

        s3=-1;
        s4=-1;
        dfs(x,0);
        dfs(s3,0);
        return s4;
    }
} graph1;
struct gg2
{
    void dfs(int x,int y)
    {
        dist[x]=0;
        for(auto f:v[x])
        {
            if(f.a!=y)
            {
                dfs(f.a,x);
                if(dist[f.a]+f.b>dist[x])
                    heavy[x]= {f.a,f.b};
                dist[x]=max(dist[x],dist[f.a]+f.b);
            }
        }
    }
    void dfs2(int x,int y)
    {
        dist3[dem]=min(dist3[dem],max(dist2[x],dist[x]));
        for(auto f:v[x])
        {
            if(f.a!=heavy[x].a&&f.a!=y)
            {
                dist2[x]=max(dist2[x],dist[f.a]+f.b);
            }
        }
        if(dist2[x]<dist[heavy[x].a])
            dist2[heavy[x].a]=dist2[x]+heavy[x].b,dfs2(heavy[x].a,x);
    }
    void get(int x)
    {
        dfs(x,0);
        dfs2(x,0);
    }
} graph2;
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    n=N;
    m=M;
    k=L;
    for(int i=1; i<=m; i++)
        l=A[i-1],r=B[i-1],s2=T[i-1],l++,r++,v[l].pb({r,s2}),v[r].pb({l,s2});
    for(int i=1; i<=n; i++)
    {
        if(!b[i])
            dem++,dist3[dem]=inf,s9=max(s9,graph1.get(i)),graph2.get(i);
    }
    sort(dist3+1,dist3+1+dem,greater<int>());
    dist3[dem+1]=-inf;
    return max({s9,dist3[1]+dist3[2]+k,dist3[2]+dist3[3]+k*2});
}
#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...