Submission #794613

# Submission time Handle Problem Language Result Execution time Memory
794613 2023-07-26T16:25:36 Z Khizri Dreaming (IOI13_dreaming) C++17
0 / 100
33 ms 14328 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=1e5+5;
int n,m,color[mxn],mx,node,node2,res,l[mxn];
vector<pii>vt[mxn];
void dfs(int u,int p,int dis){
    if(dis>=mx){
        mx=dis;
        node=u;
    }
    color[u]=1;
    for(pii v:vt[u]){
        if(v.F!=p){
            dfs(v.F,u,dis+v.S);
        }
    }
}
void dfs2(int u,int p,int dis){
    l[u]=dis;
    if(dis>=mx){
        mx=dis;
        node2=u;
    }
    for(pii v:vt[u]){
        if(v.F!=p){
            dfs2(v.F,u,dis+v.S);
        }
    }
}
bool dfs3(int u,int p,int dis){
    int q=0;
    if(u==node) q=1;
    for(pii v:vt[u]){
        if(v.F!=p&&dfs3(v.F,u,dis+v.S)){
            q=1;
            res=min(res,max(l[v.F],dis+v.S));
        }
    }
    return 1;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N,m=M;
    for(int i=0;i<m;i++){
        vt[A[i]+1].pb({B[i]+1,T[i]});
        vt[B[i]+1].pb({A[i]+1,T[i]});
    }
    vector<int>vtt;
    for(int i=1;i<=n;i++){
        if(color[i]) continue;
        mx=0,node=0;
        dfs(i,-1,0);
        mx=0,node2=0;
        dfs2(node,-1,0);
        res=mx;
        dfs3(node2,-1,0);
        vtt.pb(res);
    }
    sort(rall(vtt));
    if(vtt.size()==1) return vtt[0];
    return vtt[0]+vtt[1]+L;
}
/*
12 8 2
0 8 4
8 2 2 
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3

7 5 3
0 1 2
1 2 2
2 3 4
4 5 5 
5 6 6 
*/

Compilation message

dreaming.cpp: In function 'bool dfs3(int, int, int)':
dreaming.cpp:43:9: warning: variable 'q' set but not used [-Wunused-but-set-variable]
   43 |     int q=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6100 KB Output is correct
2 Incorrect 14 ms 6084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14328 KB Output isn't correct
2 Halted 0 ms 0 KB -