Submission #800205

# Submission time Handle Problem Language Result Execution time Memory
800205 2023-08-01T11:52:14 Z Andrey Dreaming (IOI13_dreaming) C++14
18 / 100
33 ms 14708 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

long long n,m;
vector<pair<long long,long long>> haha[100001];
vector<long long> dp(100001,-1);

long long dude(long long a, long long t, long long d) {
    long long ans = max(dp[a],d),big = 0,big2 = 0,b,c,e;
    for(long long i = 0; i < haha[a].size(); i++) {
        if(haha[a][i].first != t) {
            b = haha[a][i].first;
            c = haha[a][i].second;
            if(dp[b]+c > big) {
                big2 = big;
                big = dp[b]+c;
            }
            else if(dp[b]+c > big2) {
                big2 = dp[b]+c;
            }
        }
    }
    for(long long i = 0; i < haha[a].size(); i++) {
        if(haha[a][i].first != t) {
            b = haha[a][i].first;
            c = haha[a][i].second;
            if(c+dp[b] == big) {
                e = max(d,big2)+c;
            }
            else {
                e = max(d,big)+c;
            }
            ans = min(ans,dude(b,a,e));
        }
    }
    return ans;
}

void dfs(long long a, long long t) {
    dp[a] = 0;
    for(long long i = 0; i < haha[a].size(); i++) {
        if(haha[a][i].first != t) {
            dfs(haha[a][i].first,a);
            dp[a] = max(dp[a],dp[haha[a][i].first]+haha[a][i].second);
        }
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N;
    m = M;
    for(long long i = 0; i < m; i++) {
        haha[A[i]].push_back({B[i],T[i]});
        haha[B[i]].push_back({A[i],T[i]});
    }
    vector<long long> wut(0);
    for(long long i = 0; i < n; i++) {
        if(dp[i] == -1) {
            dfs(i,-1);
            wut.push_back(i);
        }
    }
    vector<long long> wow(0);
    for(long long i = 0; i < wut.size(); i++) {
        wow.push_back(dude(wut[i],-1,0));
    }
    sort(wow.begin(),wow.end());
    if(wow.size() == 1) {
        return wow[0];
    }
    else if(wow.size() == 2) {
        return wow[0]+wow[1]+L;
    }
    else {
        return max(wow[wow.size()-1]+wow[wow.size()-2]+L,wow[wow.size()-2]+wow[wow.size()-3]+2*L);
    }
}

Compilation message

dreaming.cpp: In function 'long long int dude(long long int, long long int, long long int)':
dreaming.cpp:11:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(long long i = 0; i < haha[a].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
dreaming.cpp:24:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(long long i = 0; i < haha[a].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs(long long int, long long int)':
dreaming.cpp:42:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(long long i = 0; i < haha[a].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:65:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(long long i = 0; i < wut.size(); i++) {
      |                          ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7360 KB Output is correct
2 Correct 16 ms 7376 KB Output is correct
3 Correct 15 ms 7380 KB Output is correct
4 Correct 15 ms 7376 KB Output is correct
5 Correct 16 ms 7376 KB Output is correct
6 Correct 23 ms 8376 KB Output is correct
7 Correct 16 ms 7508 KB Output is correct
8 Correct 16 ms 7296 KB Output is correct
9 Correct 16 ms 7296 KB Output is correct
10 Correct 16 ms 7500 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 5 ms 5704 KB Output is correct
13 Correct 5 ms 5832 KB Output is correct
14 Correct 5 ms 5748 KB Output is correct
15 Correct 5 ms 5704 KB Output is correct
16 Correct 5 ms 5704 KB Output is correct
17 Correct 5 ms 5704 KB Output is correct
18 Correct 5 ms 5832 KB Output is correct
19 Correct 5 ms 5704 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3448 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 5 ms 5704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14708 KB Output isn't correct
2 Halted 0 ms 0 KB -