Submission #947373

# Submission time Handle Problem Language Result Execution time Memory
947373 2024-03-16T04:16:09 Z adkjt Dreaming (IOI13_dreaming) C++14
0 / 100
37 ms 17620 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define f first
#define s second
#define pii pair<int,int>
vector<pii> g[111111];
int dis[111111],vis[111111],disdia[111111],cendis[111111];
vector<int> diameter[111111];
int mxi=0,mxd=0,cntg=0,st,en,mxg1=-1,mxg2=-1,mxg3=-1;
void dfs(int now,int p)
{
    vis[now]=1;
    if(dis[now]>mxd)
        mxd=dis[now],mxi=now;
    //vis[now]=1;
    for(auto x:g[now])
    {
        if(x.f==p) continue;
        dis[x.f]=dis[now]+x.s;
        dfs(x.f,now);
    }
}
bool diamake(int now,int prev,int en)
{
    diameter[cntg].push_back(now);
    if(now==en) return 1;
    for(auto x:g[now])
    {
        if(x.f==prev) continue;
        if(diamake(x.f,now,en)) return 1;
    }
    diameter[cntg].pop_back();
    return 0;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++)
    {
        g[A[i]].push_back({B[i],T[i]});
        g[B[i]].push_back({A[i],T[i]});
    }
    //for(int i=1;i<=N;i++) dis[i]=INT_MAX;
    for(int i=0;i<N;i++)
    {
        if(vis[i]) continue;
        cntg++;
        //vis[i]=1;
        mxi=-1,mxd=-1;
        dis[i]=0;
        dfs(i,-1);
        st=mxi;
        mxi=-1,mxd=-1;
        dis[st]=0;
        dfs(st,-1);
        en=mxi;
        diamake(st,-1,en);
        disdia[cntg]=mxd;
        cendis[cntg]=INT_MAX;
        for(auto x:diameter[cntg]) cendis[cntg]=min(cendis[cntg],max(dis[x],mxd-dis[x]));
        //cout<<cendis[cntg]<<'\n';
        if(mxg1==-1||cendis[cntg]>mxg1) mxg3=mxg2,mxg2=mxg1,mxg1=cendis[cntg];
        else if(mxg2==-1||cendis[cntg]>mxg2) mxg3=mxg2,mxg2=cendis[cntg];
        else if(mxg3==-1||cendis[cntg]>mxg3) mxg3=cendis[cntg];
        //cout<<st<<' '<<en<<'\n';
    }
    if(mxg3==-1) return mxg1+mxg2+L;
    return max(mxg1+mxg2+L,mxg2+mxg3+2*L);

}
/*int main()
{
    int n,m,l,a[111111],b[111111],t[111111];
    cin>>n>>m>>l;
    for(int i=0;i<m;i++)
        cin>>a[i]>>b[i]>>t[i];
    cout<<travelTime(n,m,l,a,b,t);
}*/

# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 17620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 17620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 12404 KB Output is correct
2 Correct 17 ms 12380 KB Output is correct
3 Correct 16 ms 12380 KB Output is correct
4 Correct 20 ms 12232 KB Output is correct
5 Correct 16 ms 12376 KB Output is correct
6 Correct 18 ms 12620 KB Output is correct
7 Correct 22 ms 12564 KB Output is correct
8 Correct 19 ms 12332 KB Output is correct
9 Correct 16 ms 12124 KB Output is correct
10 Correct 17 ms 12380 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 7 ms 11460 KB Output is correct
13 Correct 7 ms 11356 KB Output is correct
14 Correct 7 ms 11356 KB Output is correct
15 Correct 7 ms 11356 KB Output is correct
16 Correct 7 ms 11452 KB Output is correct
17 Correct 7 ms 11356 KB Output is correct
18 Correct 7 ms 11356 KB Output is correct
19 Correct 7 ms 11356 KB Output is correct
20 Incorrect 2 ms 8284 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 17620 KB Output isn't correct
2 Halted 0 ms 0 KB -