답안 #962057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962057 2024-04-13T06:28:20 Z danikoynov 꿈 (IOI13_dreaming) C++14
0 / 100
29 ms 12320 KB
#include "dreaming.h"
#include<bits/stdc++.h>


using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;

vector < pair < int, int > > adj[maxn];

int used[maxn], depth[maxn];
int max_depth[maxn];
void calc(int v, int p)
{
    used[v] = 1;
    max_depth[v] = 0;
    for (pair < int, int > nb : adj[v])
    {
        int u = nb.first;
        if (u == p)
            continue;
        depth[u] = depth[v] + nb.second;
        calc(u, v);
        max_depth[v] = max(max_depth[v], max_depth[u] + nb.second);
    }
}

int dist;
vector < int > ord;
void dfs(int v, int p, int lon)
{
     ord.push_back(v);
     //cout << "dfs " << v << " " << p << " " << lon << endl;
    int val = lon, sec = 0;
    for (pair < int, int > nb : adj[v])
    {
        int u = nb.first;
        if (u == p)
            continue;
        if (max_depth[u] + nb.second > val)
        {
            sec = val;
            val = max_depth[u] + nb.second;
        }
        else if (max_depth[u] + nb.second > sec)
        {
            sec = max_depth[u] + nb.second;
        }
    }
     //cout << val << " " << sec << endl;
    dist = min(dist, val);
    if (val == lon)
        return;
    for (pair < int, int > nb : adj[v])
    {
        int u = nb.first;
        if (u == p)
            continue;
        if (val == max_depth[u] + nb.second)
        {
            dfs(u, v, sec + nb.second);
            return;
        }
    }
}
int cap;

int path[maxn];
void bfs(int v)
{
     for (int w : ord)
          path[w] = -1;
     path[v] = 0;
     queue < int > q;
     q.push(v);
     while(!q.empty())
     {
          v = q.front();
          q.pop();
          for (pair <int, int > nb : adj[v])
          {
               if (path[nb.first] == -1)
               {
                    path[nb.first] = path[v] + nb.second;
                    q.push(nb.first);
               }
          }
     }
}
int find_distance(int v)
{
    calc(v, -1);
    dist = 2e9;
    ord.clear();
    dfs(v, -1, 0);

    bfs(v);
    int ds = v;
    for (int u : ord)
     if (path[u] > path[ds])
     ds = u;
    bfs(ds);
    for (int u : ord)
     if (path[u] > cap)
     cap = path[u];
    return dist;
}


int travelTime(int N, int M, int L, int A[], int B[], int T[])
{

    for (int i = 0; i < M; i ++)
    {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }

    //cout << find_distance(1) << endl;
    //exit(0);
    vector < int > values;
    for (int i = 0; i < N; i ++)
    {
        if (!used[i])
            values.push_back(find_distance(i));
    }


    //for (int cur : values)
     //cout << cur << " ";
    //cout << endl;
    sort(values.begin(), values.end());

    int sz = values.size();
    int res = values[sz - 1] + values[sz - 2] + L;
    if (sz >= 3)
        res = max(res, values[sz - 2] + values[sz - 3] + 2 * L);
     res = max(res, cap);
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 12320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 12320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 7772 KB Output is correct
2 Correct 19 ms 7772 KB Output is correct
3 Correct 17 ms 7804 KB Output is correct
4 Correct 17 ms 7772 KB Output is correct
5 Correct 17 ms 7736 KB Output is correct
6 Correct 18 ms 8156 KB Output is correct
7 Correct 24 ms 8156 KB Output is correct
8 Correct 17 ms 7744 KB Output is correct
9 Correct 18 ms 7772 KB Output is correct
10 Correct 22 ms 7888 KB Output is correct
11 Correct 1 ms 5212 KB Output is correct
12 Correct 9 ms 5848 KB Output is correct
13 Correct 9 ms 5848 KB Output is correct
14 Correct 10 ms 5976 KB Output is correct
15 Correct 9 ms 5848 KB Output is correct
16 Correct 9 ms 5844 KB Output is correct
17 Correct 10 ms 5848 KB Output is correct
18 Correct 15 ms 6052 KB Output is correct
19 Correct 10 ms 5844 KB Output is correct
20 Incorrect 1 ms 5208 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 12320 KB Output isn't correct
2 Halted 0 ms 0 KB -