답안 #426918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426918 2021-06-14T10:51:00 Z AmineWeslati 꿈 (IOI13_dreaming) C++14
14 / 100
1000 ms 14980 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(v) (int)v.size()

typedef pair<int,int>pi;
#define fi first
#define se second
typedef vector<pi>vpi;
#define eb emplace_back

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)


void ckmax(int &x, int y){x=max(x,y);}
void ckmin(int &x, int y){x=min(x,y);}

const int MX=1e5+10;
int N,M; 
vpi adj[MX];
vi vis(MX,0);

vi dist(MX);
pi par[MX]; 
void dfs(int u){
    vis[u]=1;
    for(auto it: adj[u]){
        int v=it.fi,w=it.se;
        if(dist[v]==-1){
            dist[v]=dist[u]+w;
            par[v]={u,w};
            dfs(v);
        }
    } 
}

int U,V,diam;

void solve(int u){
    FOR(i,0,N) dist[i]=-1; dist[u]=0; 
    dfs(u);
    int v=u; 
    FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; 

    u=v; 

    FOR(i,0,N) dist[i]=-1; dist[u]=0;
    dfs(u);
    v=u; 
    FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; 

    diam=dist[v];
    tie(U,V)={u,v};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ::N=N; ::M=M; 
    FOR(i,0,M){
        int u=A[i],v=B[i],w=T[i];
        adj[u].eb(v,w);
        adj[v].eb(u,w);
    }

    int ans=0;
    vi vec; 
    FOR(i,0,N) if(!vis[i]){
        solve(i);
        ckmax(ans,diam);
        
        int cur=0,mn=2e9;
        //cout << U << " " << V << endl;
        while(U!=V){
            cur+=par[V].se; 
            V=par[V].fi;

            ckmin(mn,max(diam-cur,cur));
        }
        vec.pb(mn);
    }
    ckmax(ans,vec[0]+vec[1]+L);
    return ans; 
}

/*
12
8
2
0 8 2 5 5 1 1 10
8 2 7 11 1 3 9 6
4 2 4 3 7 1 5 3

*/

/*
12
10
5
0 0 0 1 1 3 7 7 5 5 
1 2 3 4 5 6 8 9 10 11
2 3 1 4 1 6 5 5 5 5 

*/

Compilation message

dreaming.cpp: In function 'void solve(int)':
dreaming.cpp:16:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:45:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
dreaming.cpp:16:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:52:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14916 KB Output is correct
2 Correct 61 ms 14980 KB Output is correct
3 Correct 37 ms 11076 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 17 ms 5972 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 26 ms 7464 KB Output is correct
9 Correct 35 ms 9104 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 54 ms 11076 KB Output is correct
12 Correct 61 ms 12880 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14916 KB Output is correct
2 Correct 61 ms 14980 KB Output is correct
3 Correct 37 ms 11076 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 17 ms 5972 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 26 ms 7464 KB Output is correct
9 Correct 35 ms 9104 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 54 ms 11076 KB Output is correct
12 Correct 61 ms 12880 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
14 Incorrect 3 ms 3456 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 6924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14916 KB Output is correct
2 Correct 61 ms 14980 KB Output is correct
3 Correct 37 ms 11076 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 17 ms 5972 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 26 ms 7464 KB Output is correct
9 Correct 35 ms 9104 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 54 ms 11076 KB Output is correct
12 Correct 61 ms 12880 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
14 Incorrect 3 ms 3456 KB Output isn't correct
15 Halted 0 ms 0 KB -