Submission #842871

# Submission time Handle Problem Language Result Execution time Memory
842871 2023-09-03T12:39:53 Z 12345678 Dreaming (IOI13_dreaming) C++17
0 / 100
27 ms 12112 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;
int mx[nx], mxr[nx], nxt, mx1=INT_MAX, mx2=INT_MAX;
bool vs[nx];
vector<vector<pair<int, int>>> d(nx);

void dfs(int u, int p)
{
    vs[u]=1;
    for (auto [v, w]:d[u])
    {
        if (v==p) continue;
        dfs(v, u);
        mx[u]=max(mx[u], mx[v]+w);
    }
}

void dfs2(int u, int p)
{
    vector<int> pf(d[u].size()+2), sf(d[u].size()+2);
    for (int i=d[u].size()-1; i>=0; i--)
    {
        sf[i+1]=sf[i+2];
        if (d[u][i].first==p) continue;
        sf[i+1]=max(sf[i+1], d[u][i].second+mx[d[u][i].first]);
    }
    for (int i=0; i<d[u].size(); i++)
    {
        pf[i+1]=pf[i];
        if (d[u][i].first==p) continue;
        pf[i+1]=max(pf[i+1], d[u][i].second+mx[d[u][i].first]);
        mxr[d[u][i].first]=max(pf[i], sf[i+2])+d[u][i].second;
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i=0; i<M; i++) d[A[i]].push_back({B[i], T[i]}), d[B[i]].push_back({A[i], T[i]});
    dfs(0, 0); dfs2(0, 0);
    for (int i=0; i<N; i++)
    {
        if (!vs[i]) nxt=i;
        else vs[i]=0, mx1=min(mx1, max(mx[i], mxr[i]));
    }
    dfs(nxt, nxt); dfs2(nxt, nxt);
    for (int i=0; i<N; i++) if (vs[i]) mx2=min(mx2, max(mx[i], mxr[i]));
    //for (int i=0; i<N; i++) cout<<i<<' '<<mx[i]<<' '<<mxr[i]<<'\n';
    return mx1+mx2+L;
}

Compilation message

dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i=0; i<d[u].size(); i++)
      |                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 5464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -