답안 #649376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649376 2022-10-10T06:38:12 Z mychecksedad 악어의 지하 도시 (IOI11_crocodile) C++17
46 / 100
22 ms 31956 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int X = 1e6, MOD = 1e9+7;



int n, m;
vector<ll> dp(X);
vector<pair<int, ll>> g[X];
bitset<X> is, vis, calculated;

void dfs(int v, int p){
    if(is[v]){
        return;
    }
    vis[v] = 1;
    vector<pair<ll, int>> dist;
    map<int, bool> skip;
    for(auto k: g[v]){
        int u = k.first, e = k.second;
        if(u == p) continue;
        if(vis[u]){
            if(!calculated[u]) skip[u] = 1;
            continue;
        }
        dfs(u, v);
        dist.pb({dp[u] + e, u});
    }
    sort(dist.begin(), dist.end());
    for(auto k: g[v]){
        int u = k.first, e = k.second;
        if(u == p || skip[u]) continue;

        ll d;
        if(dist[0].second == u){
            if(dist.size() > 1)
                d = dist[1].first;
            else
                d = MOD;
        }else{
            d = dist[0].first;
        }
        dp[v] = max(dp[v], d);
    }
    calculated[v] = 1;
}

int travel_plan(int F, int M, int R[][2], int L[], int K, int P[]){ 
    n = F;
    m = M;
    for(int i = 0; i < K; ++i) is[P[i]] = 1;
    for(int i = 0; i < m; ++i){
        g[R[i][0]].pb({R[i][1], L[i]});
        g[R[i][1]].pb({R[i][0], L[i]});
    }
    dfs(0, 0);

    return dp[0];
}

Compilation message

crocodile.cpp: In function 'void dfs(int, int)':
crocodile.cpp:34:26: warning: unused variable 'e' [-Wunused-variable]
   34 |         int u = k.first, e = k.second;
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 16 ms 31640 KB Output is correct
3 Correct 17 ms 31616 KB Output is correct
4 Correct 16 ms 31700 KB Output is correct
5 Correct 16 ms 31672 KB Output is correct
6 Correct 16 ms 31700 KB Output is correct
7 Correct 18 ms 31708 KB Output is correct
8 Correct 17 ms 31792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 16 ms 31640 KB Output is correct
3 Correct 17 ms 31616 KB Output is correct
4 Correct 16 ms 31700 KB Output is correct
5 Correct 16 ms 31672 KB Output is correct
6 Correct 16 ms 31700 KB Output is correct
7 Correct 18 ms 31708 KB Output is correct
8 Correct 17 ms 31792 KB Output is correct
9 Incorrect 22 ms 31956 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 16 ms 31640 KB Output is correct
3 Correct 17 ms 31616 KB Output is correct
4 Correct 16 ms 31700 KB Output is correct
5 Correct 16 ms 31672 KB Output is correct
6 Correct 16 ms 31700 KB Output is correct
7 Correct 18 ms 31708 KB Output is correct
8 Correct 17 ms 31792 KB Output is correct
9 Incorrect 22 ms 31956 KB Output isn't correct
10 Halted 0 ms 0 KB -