답안 #153709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153709 2019-09-15T09:33:10 Z Ruxandra985 꿈 (IOI13_dreaming) C++14
14 / 100
77 ms 12536 KB
#include <cstdio>
#include <vector>
#include "dreaming.h"
#include <algorithm>
#define DIMN 100010
using namespace std;
int f[DIMN] , vc , rc,dist[DIMN] , a[DIMN] , b[DIMN] , c[DIMN];
vector <pair <int,int> > v[DIMN];
pair <int,int> arb[DIMN];
int dfs_initial (int nod , int ok){ /// return diametru arbore + calcul distante
    int i,vecin , maxi1, maxi2;
    f[nod] = 1;
    for (i=0;i<v[nod].size();i++){
        vecin = v[nod][i].first;
        if (!f[vecin]){
            dfs_initial (vecin , 0);
            dist[nod] = max (dist[nod] , dist[vecin] + v[nod][i].second);
        }
    }
    if (ok == 1){ /// acum aflam diametrul
        if (v[nod].size() == 1){
            return dist[nod];
        }
        maxi1 = maxi2 = 0;
        for (i=0;i<v[nod].size();i++){
            vecin = v[nod][i].first;
            if (maxi1 < dist[vecin] + v[nod][i].second){
                maxi2 = maxi1;
                maxi1 = dist[vecin] + v[nod][i].second;
            }
            else if (maxi2 < dist[vecin] + v[nod][i].second){
                maxi2 = dist[vecin] + v[nod][i].second;
            }
        }
        return maxi1 + maxi2; /// diametrul arborelui curent
    }
    else return 0;
}
void dfs_process (int nod, int tt, int dup){
    int i,vecin , maxi1 , maxi2 , pmaxi1;
    /// daca il faci pe nod radacina , dmax e fie dist[nod] fie dup
    if (vc > max (dist[nod] , dup)){
        vc = max(dist[nod] , dup);
        rc = nod;
    }
    maxi1 = maxi2 = 0;
    pmaxi1 = 0;
    for (i=0;i<v[nod].size();i++){
        vecin = v[nod][i].first;
        if (vecin == tt)
            continue;
        if (maxi1 < dist[vecin] + v[nod][i].second){
            maxi2 = maxi1;
            maxi1 = dist[vecin] + v[nod][i].second;
            pmaxi1 = vecin;
        }
        else if (maxi2 < dist[vecin] + v[nod][i].second){
            maxi2 = dist[vecin] + v[nod][i].second;
        }
    }
    for (i=0;i<v[nod].size();i++){
        vecin = v[nod][i].first;
        if (vecin==tt)
            continue;
        if (vecin == pmaxi1)
            dfs_process (vecin , nod , v[nod][i].second + max (dup , maxi2));
        else
            dfs_process (vecin , nod , v[nod][i].second + max (dup , maxi1));
    }

}
int travelTime (int n , int m , int l , int a[] , int b[] , int c[]){
    int i , elem , inter , diam_max;
    elem = 0;
    for (i=1;i<=m;i++){
        a[i-1]++;
        b[i-1]++;
        v[a[i-1]].push_back(make_pair(b[i-1] , c[i-1]));
        v[b[i-1]].push_back(make_pair(a[i-1] , c[i-1]));
    }
    for (i=1;i<=n;i++){
        if (!f[i]){
            diam_max = max (diam_max , dfs_initial(i,1));
            vc = 2000000000;
            dfs_process (i, 0 , 0);
            /// vc rc = valoarea arborelui curent + radacina fixata
            arb[++elem] = make_pair(vc,rc);
        }
    }
    sort (arb + 1, arb + elem + 1); /// le uneste in ord descresc a vc
    inter = 0;
    for (i=elem - 1 ; i; i--){
        inter = max (inter , (elem - i) * l + arb[elem].first + arb[i].first);
    }
    return max(diam_max , inter);
}

Compilation message

dreaming.cpp: In function 'int dfs_initial(int, int)':
dreaming.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[nod].size();i++){
              ~^~~~~~~~~~~~~~
dreaming.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i=0;i<v[nod].size();i++){
                  ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs_process(int, int, int)':
dreaming.cpp:48:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[nod].size();i++){
              ~^~~~~~~~~~~~~~
dreaming.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[nod].size();i++){
              ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:73:28: warning: 'diam_max' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int i , elem , inter , diam_max;
                            ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12536 KB Output is correct
2 Correct 66 ms 12152 KB Output is correct
3 Correct 49 ms 10744 KB Output is correct
4 Correct 15 ms 4088 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 19 ms 4856 KB Output is correct
7 Correct 4 ms 2684 KB Output is correct
8 Correct 35 ms 6776 KB Output is correct
9 Correct 45 ms 9080 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 77 ms 10016 KB Output is correct
12 Correct 68 ms 11128 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12536 KB Output is correct
2 Correct 66 ms 12152 KB Output is correct
3 Correct 49 ms 10744 KB Output is correct
4 Correct 15 ms 4088 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 19 ms 4856 KB Output is correct
7 Correct 4 ms 2684 KB Output is correct
8 Correct 35 ms 6776 KB Output is correct
9 Correct 45 ms 9080 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 77 ms 10016 KB Output is correct
12 Correct 68 ms 11128 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2684 KB Output is correct
19 Correct 4 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Incorrect 4 ms 2680 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12536 KB Output is correct
2 Correct 66 ms 12152 KB Output is correct
3 Correct 49 ms 10744 KB Output is correct
4 Correct 15 ms 4088 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 19 ms 4856 KB Output is correct
7 Correct 4 ms 2684 KB Output is correct
8 Correct 35 ms 6776 KB Output is correct
9 Correct 45 ms 9080 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 77 ms 10016 KB Output is correct
12 Correct 68 ms 11128 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2684 KB Output is correct
19 Correct 4 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Incorrect 4 ms 2680 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 6728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12536 KB Output is correct
2 Correct 66 ms 12152 KB Output is correct
3 Correct 49 ms 10744 KB Output is correct
4 Correct 15 ms 4088 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 19 ms 4856 KB Output is correct
7 Correct 4 ms 2684 KB Output is correct
8 Correct 35 ms 6776 KB Output is correct
9 Correct 45 ms 9080 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 77 ms 10016 KB Output is correct
12 Correct 68 ms 11128 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Incorrect 23 ms 2876 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12536 KB Output is correct
2 Correct 66 ms 12152 KB Output is correct
3 Correct 49 ms 10744 KB Output is correct
4 Correct 15 ms 4088 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 19 ms 4856 KB Output is correct
7 Correct 4 ms 2684 KB Output is correct
8 Correct 35 ms 6776 KB Output is correct
9 Correct 45 ms 9080 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 77 ms 10016 KB Output is correct
12 Correct 68 ms 11128 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2684 KB Output is correct
19 Correct 4 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Incorrect 4 ms 2680 KB Output isn't correct
23 Halted 0 ms 0 KB -