Submission #745813

# Submission time Handle Problem Language Result Execution time Memory
745813 2023-05-21T08:11:28 Z yeyso Dreaming (IOI13_dreaming) C++14
14 / 100
207 ms 50076 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj; vector<vector<int>> dmj; vector<int> dist; vector<int> dist2; vector<set<pair<int, int>>> components; vector<set<pair<int, int>>> components2; vector<int> parents;
void dfs(int node, int parent, int distance, int component, int mode){
    if(mode == 0) components[component].insert({distance, node});
    if(mode == 1) {
        components2[component].insert({distance, node});
        parents[node] = parent;
    }
    dist[node] = distance;
    for(int i = 0; i < adj[node].size(); i ++){
        if(adj[node][i] != parent){
            dfs(adj[node][i], node, distance + dmj[node][i], component, mode);
        }
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<vector<int>> adj0(N, vector<int>()); vector<vector<int>> dmj0(N, vector<int>());
    for(int i = 0; i < M; i ++){
        adj0[A[i]].push_back(B[i]); adj0[B[i]].push_back(A[i]);
        dmj0[A[i]].push_back(T[i]); dmj0[B[i]].push_back(T[i]);
    }
    vector<int> dist0(N, INT_MAX / 2);
    adj = adj0; dmj = dmj0; dist = dist0; dist2 = dist0;
    int component_ = 0;
    vector<int> parents0(N, -1); parents = parents0;
    for(int i = 0; i < N; i ++){
        if(dist[i] >= INT_MAX / 2){
            components.push_back({}); components2.push_back({});
            dist[i] = 0;
            dfs(i, -1, 0, component_, 0);
            component_ += 1;
        }
    }
    for(int i = 0; i < components.size(); i ++){
        //cout << (*(--components[i].end())).second << " ";
        dfs((*(--components[i].end())).second, -1, 0, i, 1);
    } //cout << "\n";
    int furtherest = 0; int mid = 0; int mid2 = 0; int split = 0; int furtherest_node = 0;
    set<pair<int, int>> components3;
    vector<set<pair<int, int>>> components4(N, set<pair<int, int>>());
    int cur = 0;
    for(int i = 0; i < components2.size(); i ++){
        furtherest = (*(--components2[i].end())).first;
        furtherest_node = (*(--components2[i].end())).second;
        cur = furtherest_node;
        while(cur > -1){
            //components2.erase({cur, })
            components4[i].insert({dist[cur], cur});
            cur = parents[cur];
        }
        //cout << (*(--components4[i].end())).second << " ";
        mid = (*(components4[i].lower_bound({furtherest / 2, 0}))).first;
        mid2 = (*(--components4[i].lower_bound({furtherest / 2, 0}))).first;
        if(abs(furtherest - mid) > abs(furtherest - mid2)){ split = mid2;
        } else { split = mid; }
        if(split > furtherest / 2) components3.insert({split, furtherest - split}); 
        if(split <= furtherest / 2) components3.insert({furtherest - split, split});
    }
    int maxacross = (*(--components3.end())).first + (*(----components3.end())).first + L;
    int maxwithin = (*(--components3.end())).first + (*(--components3.end())).second;
    return max(maxacross, maxwithin);
    /*for(int i = 0; i < parents.size(); i ++){
        cout << i << " ";
    } cout << "\n";
    for(int i = 0; i < parents.size(); i ++){
        cout << parents[i] << " ";
    }*/
}
/*
g++ -DEVAL -static -O2 -o dreaming grader.cpp dreaming.cpp

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

*/

Compilation message

dreaming.cpp: In function 'void dfs(int, int, int, int, int)':
dreaming.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < adj[node].size(); i ++){
      |                    ~~^~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 0; i < components.size(); i ++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
dreaming.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0; i < components2.size(); i ++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 207 ms 50076 KB Output is correct
2 Correct 173 ms 50020 KB Output is correct
3 Correct 93 ms 33020 KB Output is correct
4 Correct 19 ms 7564 KB Output is correct
5 Correct 15 ms 5204 KB Output is correct
6 Correct 28 ms 11188 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 77 ms 20620 KB Output is correct
9 Correct 81 ms 26572 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 118 ms 36544 KB Output is correct
12 Correct 158 ms 42872 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 207 ms 50076 KB Output is correct
2 Correct 173 ms 50020 KB Output is correct
3 Correct 93 ms 33020 KB Output is correct
4 Correct 19 ms 7564 KB Output is correct
5 Correct 15 ms 5204 KB Output is correct
6 Correct 28 ms 11188 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 77 ms 20620 KB Output is correct
9 Correct 81 ms 26572 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 118 ms 36544 KB Output is correct
12 Correct 158 ms 42872 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 42916 KB Output is correct
2 Incorrect 82 ms 43120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 207 ms 50076 KB Output is correct
2 Correct 173 ms 50020 KB Output is correct
3 Correct 93 ms 33020 KB Output is correct
4 Correct 19 ms 7564 KB Output is correct
5 Correct 15 ms 5204 KB Output is correct
6 Correct 28 ms 11188 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 77 ms 20620 KB Output is correct
9 Correct 81 ms 26572 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 118 ms 36544 KB Output is correct
12 Correct 158 ms 42872 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Halted 0 ms 0 KB -