답안 #70262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70262 2018-08-22T14:21:34 Z MANcity 꿈 (IOI13_dreaming) C++14
0 / 100
80 ms 12280 KB
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
#include "dreaming.h"
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
vector<vector<pair<int,int> > > g(100002);
int max1[100002];
int pos[100002];
int max2[100002];
int verHi[100002];
int used[100002];
int ANSWER;
int DIAM=0;
void dfs_fordown(int v,int p)
{
    used[v]=1;
    for0(j,g[v].size()-1)
    {
        int to=g[v][j].first;
        int len=g[v][j].second;
        if(to!=p)
        {
            dfs_fordown(to,v);
            if((max1[to]+len)>=max1[v])
            {
                max2[v]=max1[v];
                max1[v]=(max1[to]+len);
                pos[v]=to;
            }
            else
            {
                if((max1[to]+len)>max2[v])
                    max2[v]=max1[to]+len;
            }
        }
    }
}
int dfs_forup(int v,int p,int lenpar)
{
    if(p!=-1)
    {
        if(pos[p]==v)
            verHi[v]=max(verHi[p],max2[p])+lenpar;
        else
            verHi[v]=max(verHi[p],max1[p])+lenpar;
    }
    for0(j,g[v].size()-1)
    {
        int to=g[v][j].first;
        int len=g[v][j].second;
        if(to!=p)
        {
            dfs_forup(to,v,len);
        }
    }
    //cout<<v<<" "<<verHi[v]<<" "<<max1[v]<<endl;
    ANSWER=min(ANSWER,max(verHi[v],max1[v]));
    DIAM=max(DIAM,max(verHi[v],max1[v]));
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for0(i,M-1)
    {
        g[A[i]].pb({B[i],T[i]});
        g[B[i]].pb({A[i],T[i]});
    }
    vector<int> D;
    int ANS=0;
    for0(i,N-1)
    {
        if(used[i]==0)
        {
            DIAM=0;
            ANSWER=1000000002;
            dfs_fordown(i,-1);
            dfs_forup(i,-1,0);
            ANS=max(ANS,DIAM);
            D.push_back(ANSWER);
        }
    }
    int l=D.size();
    if(l==1)
        return max(ANS,D[0]);
    if(l==2)
        return (D[0]+D[1]+L,ANS);
    sort(D.begin(),D.end());
    ANS=(D[l-1]+D[l-2]+L);
    ANS=max(ANS,D[l-2]+D[l-3]+L+L);
    return ANS;
}
/*
7 5
1
0 1 30
0 2 2
0 3 30
4 5 4
4 6 5
*/

Compilation message

dreaming.cpp: In function 'int dfs_forup(int, int, int)':
dreaming.cpp:77:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:102:26: warning: value computed is not used [-Wunused-value]
         return (D[0]+D[1]+L,ANS);
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12280 KB Output is correct
2 Correct 72 ms 12024 KB Output is correct
3 Correct 41 ms 10488 KB Output is correct
4 Correct 11 ms 4096 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4864 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12280 KB Output is correct
2 Correct 72 ms 12024 KB Output is correct
3 Correct 41 ms 10488 KB Output is correct
4 Correct 11 ms 4096 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4864 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12280 KB Output is correct
2 Correct 72 ms 12024 KB Output is correct
3 Correct 41 ms 10488 KB Output is correct
4 Correct 11 ms 4096 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4864 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 7296 KB Output is correct
2 Correct 33 ms 7288 KB Output is correct
3 Correct 28 ms 7296 KB Output is correct
4 Correct 29 ms 7296 KB Output is correct
5 Correct 31 ms 7168 KB Output is correct
6 Correct 29 ms 7808 KB Output is correct
7 Correct 37 ms 7416 KB Output is correct
8 Correct 30 ms 7160 KB Output is correct
9 Correct 27 ms 7140 KB Output is correct
10 Correct 30 ms 7412 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 8 ms 4956 KB Output is correct
13 Correct 9 ms 5112 KB Output is correct
14 Correct 8 ms 4984 KB Output is correct
15 Correct 8 ms 4984 KB Output is correct
16 Correct 8 ms 4856 KB Output is correct
17 Correct 8 ms 4092 KB Output is correct
18 Correct 9 ms 5240 KB Output is correct
19 Correct 9 ms 4860 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Incorrect 4 ms 2688 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12280 KB Output is correct
2 Correct 72 ms 12024 KB Output is correct
3 Correct 41 ms 10488 KB Output is correct
4 Correct 11 ms 4096 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4864 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12280 KB Output is correct
2 Correct 72 ms 12024 KB Output is correct
3 Correct 41 ms 10488 KB Output is correct
4 Correct 11 ms 4096 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 4864 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -