Submission #37938

# Submission time Handle Problem Language Result Execution time Memory
37938 2017-12-29T11:55:54 Z 14kg Dreaming (IOI13_dreaming) C++11
0 / 100
72 ms 10332 KB
#include "dreaming.h"
#include <vector>
#include <algorithm>
#define N 100001
#define INF 2000000000

using namespace std;
int n, L, out, max_len, MAX[4], gd[N];
bool check[N], gd_check[N];
vector<pair<int,int> > r[N];

int max_f(int x, int y) { return x>y?x:y; }
int min_f(int x, int y) { return x<y?x:y; }

int g(int lev, int up_node){
    if(!gd_check[lev]){
        gd_check[lev]=true;
        for(vector<pair<int,int> >::iterator it=r[lev].begin(); it!=r[lev].end(); it++)
            if(it->first!=up_node) gd[lev]=max_f(gd[lev],it->second+g(it->first,lev));
    }
    return gd[lev];
}
void f(int lev, int up_len){
    int max1=0, max2=0, path, temp;

    check[lev]=true;
    for(vector<pair<int,int> >::iterator it=r[lev].begin(); it!=r[lev].end(); it++) {
        if(!check[it->first]) temp=g(it->first,lev)+it->second;
        else temp=up_len;

        if(max1<temp){
            max2=max1, max1=temp;
            path=it->first;
        }
        else if(max2<temp) max2=temp;
    }
    out=max_f(out,max1+max2);
    max_len=min_f(max_len,max1);

    for(vector<pair<int,int> >::iterator it=r[lev].begin(); it!=r[lev].end(); it++)
        if(!check[it->first]) f(it->first,(path==it->first?max2:max1)+it->second);
}

int travelTime(int _n, int m, int _L, int _a[], int _b[], int _t[]) {
    int x, y;

    n=_n, L=_L;
    for(int i=0; i<m; i++){
        x=_a[i]+1, y=_b[i]+1;
        r[x].push_back({y,_t[i]}), r[y].push_back({x,_t[i]});
    }

    for(int i=1; i<=n; i++)
        if(!check[i]){
            max_len=INF, f(i,0);

            MAX[0]=max_len, sort(MAX+0,MAX+4);
        }
    return max_f(out,max_f(MAX[3]+MAX[2]+L,MAX[2]+MAX[1]+L+L));
}

Compilation message

dreaming.cpp: In function 'void f(int, int)':
dreaming.cpp:41:59: warning: 'path' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(!check[it->first]) f(it->first,(path==it->first?max2:max1)+it->second);
                                           ~~~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 72 ms 10332 KB Output is correct
2 Correct 65 ms 10104 KB Output is correct
3 Correct 43 ms 8824 KB Output is correct
4 Correct 11 ms 3768 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 10332 KB Output is correct
2 Correct 65 ms 10104 KB Output is correct
3 Correct 43 ms 8824 KB Output is correct
4 Correct 11 ms 3768 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 10332 KB Output is correct
2 Correct 65 ms 10104 KB Output is correct
3 Correct 43 ms 8824 KB Output is correct
4 Correct 11 ms 3768 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5248 KB Output is correct
2 Correct 24 ms 5248 KB Output is correct
3 Correct 24 ms 5120 KB Output is correct
4 Correct 29 ms 5120 KB Output is correct
5 Correct 25 ms 5120 KB Output is correct
6 Correct 31 ms 5368 KB Output is correct
7 Correct 28 ms 5340 KB Output is correct
8 Correct 26 ms 5120 KB Output is correct
9 Correct 25 ms 5120 KB Output is correct
10 Correct 27 ms 5248 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 6 ms 2944 KB Output is correct
13 Correct 6 ms 2944 KB Output is correct
14 Correct 6 ms 2816 KB Output is correct
15 Correct 5 ms 2944 KB Output is correct
16 Correct 5 ms 2816 KB Output is correct
17 Correct 5 ms 2816 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 5 ms 2944 KB Output is correct
20 Incorrect 4 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 10332 KB Output is correct
2 Correct 65 ms 10104 KB Output is correct
3 Correct 43 ms 8824 KB Output is correct
4 Correct 11 ms 3768 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 10332 KB Output is correct
2 Correct 65 ms 10104 KB Output is correct
3 Correct 43 ms 8824 KB Output is correct
4 Correct 11 ms 3768 KB Output is correct
5 Correct 9 ms 3328 KB Output is correct
6 Correct 17 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -