답안 #842933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842933 2023-09-03T13:36:44 Z 12345678 꿈 (IOI13_dreaming) C++17
0 / 100
1000 ms 19024 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

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

void dfs(int u, int p)
{
    vs[u]=vsc[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);
    pf[0]=mxr[u];
    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;
    }
    for (auto [v, w]:d[u]) if (v!=p) dfs2(v, u);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    if (N==1) return 0;
    if (N==2&&M==1) return T[0];
    if (N==2) return L;
    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]});
    while (nxt!=-1)
    {
        dfs(nxt, nxt); dfs2(nxt, nxt);
        nxt=-1; cmx=INT_MAX;
        for (int i=0; i<N; i++) if (!vs[i]) nxt=i;
        for (int i=0; i<N; i++) if (vsc[i]) vsc[i]=0, cmx=min(cmx, max(mx[i], mxr[i]));
        b[cnt++]=cmx;
    }
    for (int i=0; i<N; i++) ans=max(ans, mx[i]+mxr[i]);
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    return max(ans, max(b[0]+L+b[1], b[1]+2*L+b[2]));
}

Compilation message

dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:33: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]
   33 |     for (int i=0; i<d[u].size(); i++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 19024 KB Output is correct
2 Correct 46 ms 18192 KB Output is correct
3 Correct 41 ms 17500 KB Output is correct
4 Correct 8 ms 5468 KB Output is correct
5 Correct 7 ms 4440 KB Output is correct
6 Correct 16 ms 6496 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 3 ms 3164 KB Output is correct
3 Incorrect 2 ms 3160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 19024 KB Output is correct
2 Correct 46 ms 18192 KB Output is correct
3 Correct 41 ms 17500 KB Output is correct
4 Correct 8 ms 5468 KB Output is correct
5 Correct 7 ms 4440 KB Output is correct
6 Correct 16 ms 6496 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1034 ms 6092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 3 ms 3164 KB Output is correct
3 Incorrect 2 ms 3160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 19024 KB Output is correct
2 Correct 46 ms 18192 KB Output is correct
3 Correct 41 ms 17500 KB Output is correct
4 Correct 8 ms 5468 KB Output is correct
5 Correct 7 ms 4440 KB Output is correct
6 Correct 16 ms 6496 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -