Submission #293194

# Submission time Handle Problem Language Result Execution time Memory
293194 2020-09-07T18:09:40 Z alexandra_udristoiu Dreaming (IOI13_dreaming) C++14
0 / 100
63 ms 11640 KB
#include "dreaming.h"
#include<algorithm>
#include<vector>
#define DIM 100005
#define f first
#define s second
using namespace std;
static int viz[DIM], w[DIM], df[DIM], d[DIM][2], nr;
static vector< pair<int, int> > v[DIM];
static void dfs1(int nod){
    viz[nod] = 1;
    d[nod][0] = d[nod][1] = 0;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 0){
            dfs1(vecin);
            if(d[vecin][0] + v[nod][i].s > d[nod][0]){
                d[nod][1] = d[nod][0];
                d[nod][0] = d[vecin][0] + v[nod][i].s;
            }
            else{
                d[nod][1] = max(d[nod][1], d[vecin][0] + v[nod][i].s);
            }
        }
    }
}
static void dfs2(int nod){
    viz[nod] = 2;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 1){
            df[vecin] = df[nod] + v[nod][i].s;
            if(d[nod][0] != d[vecin][0] + v[nod][i].s){
                df[vecin] = max(df[vecin], d[nod][0] + v[nod][i].s);
            }
            else{
                df[vecin] = max(df[vecin], d[nod][1] + v[nod][i].s);
            }
            w[nr] = min(w[nr], max(d[vecin][0], df[vecin]) );
            dfs2(vecin);
        }
    }
}

int travelTime(int n, int m, int k, int a[], int b[], int t[]) {
    int i, sol;
    for(i = 0; i < m; i++){
        v[ a[i] ].push_back( make_pair(b[i], t[i]) );
        v[ b[i] ].push_back( make_pair(a[i], t[i]) );
    }
    for(i = 0; i < n; i++){
        if(viz[i] == 0){
            dfs1(i);
        }
    }
    for(i = 0; i < n; i++){
        if(viz[i] == 1){
            nr++;
            w[nr] = d[i][0];
            dfs2(i);
        }
    }
    sort(w + 1, w + nr + 1);
    sol = max(w[nr] + w[nr - 1] + k, w[nr - 1] + w[nr - 2] + 2 * k);
    return sol;
}

Compilation message

dreaming.cpp: In function 'void dfs1(int)':
dreaming.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int)':
dreaming.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 11640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 11640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 11640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 7160 KB Output is correct
2 Correct 29 ms 7160 KB Output is correct
3 Correct 30 ms 7160 KB Output is correct
4 Correct 29 ms 7160 KB Output is correct
5 Correct 29 ms 7168 KB Output is correct
6 Correct 31 ms 7416 KB Output is correct
7 Correct 32 ms 7288 KB Output is correct
8 Correct 29 ms 7032 KB Output is correct
9 Correct 33 ms 7032 KB Output is correct
10 Correct 30 ms 7288 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 6 ms 4608 KB Output is correct
13 Correct 6 ms 4608 KB Output is correct
14 Correct 6 ms 4736 KB Output is correct
15 Correct 6 ms 4608 KB Output is correct
16 Correct 5 ms 4480 KB Output is correct
17 Correct 5 ms 4352 KB Output is correct
18 Correct 6 ms 4608 KB Output is correct
19 Correct 5 ms 4608 KB Output is correct
20 Incorrect 2 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 11640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 11640 KB Output isn't correct
2 Halted 0 ms 0 KB -