Submission #794618

# Submission time Handle Problem Language Result Execution time Memory
794618 2023-07-26T16:42:07 Z Khizri Dreaming (IOI13_dreaming) C++17
18 / 100
34 ms 14316 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);
        }
    }
}
void dfs3(int u,int p,int dis){
    int q=0;
    if(u==node) q=1;
    for(pii v:vt[u]){
        if(v.F!=p){
            q=1;
            dfs3(v.F,u,dis+v.S);
            res=min(res,max(l[v.F],dis+v.S));
        }
    }
}
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];
    int ans=vtt[0]+vtt[1]+L;
    if(vtt.size()>2){
        ans=max(ans,vtt[1]+vtt[2]+2*L);
    }
    return ans;
}
/*
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 'void 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 34 ms 14316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 14316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 6064 KB Output is correct
2 Correct 14 ms 6100 KB Output is correct
3 Correct 14 ms 6040 KB Output is correct
4 Correct 16 ms 6036 KB Output is correct
5 Correct 14 ms 6100 KB Output is correct
6 Correct 16 ms 6488 KB Output is correct
7 Correct 14 ms 6204 KB Output is correct
8 Correct 14 ms 5976 KB Output is correct
9 Correct 14 ms 5972 KB Output is correct
10 Correct 24 ms 6124 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 4 ms 4048 KB Output is correct
13 Correct 4 ms 4048 KB Output is correct
14 Correct 4 ms 4048 KB Output is correct
15 Correct 5 ms 4076 KB Output is correct
16 Correct 4 ms 4048 KB Output is correct
17 Correct 5 ms 3920 KB Output is correct
18 Correct 4 ms 4048 KB Output is correct
19 Correct 4 ms 4048 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 4 ms 4048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 14316 KB Output isn't correct
2 Halted 0 ms 0 KB -