Submission #551362

# Submission time Handle Problem Language Result Execution time Memory
551362 2022-04-20T13:44:01 Z razvan Dreaming (IOI13_dreaming) C++14
14 / 100
64 ms 16644 KB
#include "dreaming.h"
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <algorithm>
#define pb push_back

using namespace std;
const int maxn = 100005;

struct xy {
    int x, y;
};
vector<xy> v[maxn];
int done[maxn];
int bgst[maxn], ibgst[maxn];
//int ibgst2[maxn];
int now = -1, inow;
//int lft, rgh;
int ansnow, iansnow;
void dfs(int x, int p) {
    done[x] = true;
    
    int big1 = 0, big2 = 0, ibig1 = -1, ibig2 = -1;
    for(auto u : v[x]) {
        if(u.x != p) {
            dfs(u.x, x);
            if(bgst[u.x] + u.y > big1) {
                big2 = big1;
                ibig2 = ibig1;

                big1 = bgst[u.x] + u.y;
                ibig1 = u.x;
            } else if(bgst[u.x] + u.y > big2) {
                big2 = bgst[u.x] + u.y;
                ibig2 = u.x;
            }
        }
    }
    bgst[x] = big1;
    ibgst[x] = ibig1;
    //ibgst2[x] = ibig2;
    if(big1 + big2 > now) {
        now = big1 + big2;
        inow = x;
    }
}
void dfs2(int x) {
    if(max(bgst[x], now - bgst[x]) < ansnow) {
        ansnow = max(bgst[x], now - bgst[x]);
        iansnow = x;
    }

    if(ibgst[x] != -1)
        dfs2(ibgst[x]);
}
vector<int> points;
int best = -1, ibest;
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    int i, j;
    for(i = 0; i < m; i ++) {
        v[a[i]].pb({b[i], t[i]});
        v[b[i]].pb({a[i], t[i]});
    }
    for(i = 0; i < n; i ++) {
        if(done[i] == false) {
            done[i] = true;
            now = -1;
            dfs(i, 0);
            //lft = bgst[inow];
            //rgh = now - lft;
            ansnow = bgst[inow];
            iansnow = i;

            //cout << "now: " << now << ' ' << inow << "  " << ansnow << ' ' << iansnow << '\n';
            dfs2(ibgst[inow]);
            //cout << "ansnow: " << ansnow << ' ' << iansnow << '\n';

            points.pb(iansnow);
            if(ansnow > best) {
                best = ansnow;
                ibest = iansnow;
            }
        }
    }
    
    for(auto w : points) {
        if(w != ibest) {
            v[ibest].pb({w, l});
            v[w].pb({ibest, l});
        }
    }
    for(i = 0; i < n; i ++) {
        bgst[i] = ibgst[i] = 0;
        //ibgst2[i] = 0;
    }
    now = -1;
    dfs(1, 0);
    
    return now;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:25:41: warning: variable 'ibig2' set but not used [-Wunused-but-set-variable]
   25 |     int big1 = 0, big2 = 0, ibig1 = -1, ibig2 = -1;
      |                                         ^~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:61:12: warning: unused variable 'j' [-Wunused-variable]
   61 |     int i, j;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 45 ms 15308 KB Output is correct
2 Correct 46 ms 16644 KB Output is correct
3 Correct 29 ms 11632 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 3668 KB Output is correct
6 Correct 11 ms 5752 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 24 ms 7116 KB Output is correct
9 Correct 27 ms 9676 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 42 ms 11724 KB Output is correct
12 Correct 64 ms 14492 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2664 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Incorrect 2 ms 2664 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 15308 KB Output is correct
2 Correct 46 ms 16644 KB Output is correct
3 Correct 29 ms 11632 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 3668 KB Output is correct
6 Correct 11 ms 5752 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 24 ms 7116 KB Output is correct
9 Correct 27 ms 9676 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 42 ms 11724 KB Output is correct
12 Correct 64 ms 14492 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2664 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Incorrect 2 ms 2664 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 8180 KB Output is correct
2 Correct 22 ms 8132 KB Output is correct
3 Correct 22 ms 8200 KB Output is correct
4 Correct 25 ms 8252 KB Output is correct
5 Correct 35 ms 8220 KB Output is correct
6 Correct 29 ms 8996 KB Output is correct
7 Correct 28 ms 8392 KB Output is correct
8 Correct 25 ms 8136 KB Output is correct
9 Correct 24 ms 7964 KB Output is correct
10 Correct 25 ms 8388 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 10 ms 8164 KB Output is correct
13 Correct 11 ms 8264 KB Output is correct
14 Correct 10 ms 8136 KB Output is correct
15 Correct 10 ms 8128 KB Output is correct
16 Correct 10 ms 8136 KB Output is correct
17 Correct 10 ms 8136 KB Output is correct
18 Correct 11 ms 8168 KB Output is correct
19 Correct 10 ms 8136 KB Output is correct
20 Correct 2 ms 2660 KB Output is correct
21 Incorrect 2 ms 2664 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2664 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Incorrect 2 ms 2664 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 15308 KB Output is correct
2 Correct 46 ms 16644 KB Output is correct
3 Correct 29 ms 11632 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 3668 KB Output is correct
6 Correct 11 ms 5752 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 24 ms 7116 KB Output is correct
9 Correct 27 ms 9676 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 42 ms 11724 KB Output is correct
12 Correct 64 ms 14492 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2664 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Incorrect 2 ms 2664 KB Output isn't correct
20 Halted 0 ms 0 KB -