Submission #434946

# Submission time Handle Problem Language Result Execution time Memory
434946 2021-06-22T12:43:59 Z alextodoran Dreaming (IOI13_dreaming) C++17
18 / 100
77 ms 14148 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

typedef long long ll;

struct Edge
{
    int to;
    int len;
};

int travelTime (int n, int m, int lenNew, int edgeU[], int edgeV[], int edgeL[])
{
    vector <Edge> edges[n];
    for(int i = 0; i < m; i++)
    {
        edges[edgeU[i]].push_back(Edge{edgeV[i], edgeL[i]});
        edges[edgeV[i]].push_back(Edge{edgeU[i], edgeL[i]});
    }

    vector <int> centers;
    vector <int> weights;
    {
        int plen[n];

        int maxDistUp[n];
        int maxDistDown[n];
        int maxDistDown2[n];

        bool visited[n];
        vector <int> nodes;
        function <void (int, int)> DFSDown = [&] (int u, int parent)
        {
            nodes.push_back(u);
            visited[u] = true;

            maxDistDown[u] = 0;
            maxDistDown2[u] = 0;
            for(Edge e : edges[u])
                if(e.to != parent)
                {
                    plen[e.to] = e.len;
                    DFSDown(e.to, u);
                    if(maxDistDown[e.to] + e.len >= maxDistDown[u])
                    {
                        maxDistDown2[u] = maxDistDown[u];
                        maxDistDown[u] = maxDistDown[e.to] + e.len;
                    }
                    else if(maxDistDown[e.to] + e.len > maxDistDown2[u])
                        maxDistDown2[u] = maxDistDown[e.to] + e.len;
                }
        };
        function <void (int, int)> DFSUp = [&] (int u, int parent)
        {
            if(parent != -1)
            {
                maxDistUp[u] = maxDistUp[parent] + plen[u];
                if(maxDistDown[u] + plen[u] == maxDistDown[parent])
                    maxDistUp[u] = max(maxDistUp[u], maxDistDown2[parent] + plen[u]);
                else
                    maxDistUp[u] = max(maxDistUp[u], maxDistDown[parent] + plen[u]);
            }
            else
                maxDistUp[u] = 0;

            for(Edge e : edges[u])
                if(e.to != parent)
                    DFSUp(e.to, u);
        };
        for(int u = 0; u < n; u++)
            visited[u] = false;
        for(int u = 0; u < n; u++)
            if(visited[u] == false)
            {
                nodes.clear();
                DFSDown(u, -1);
                DFSUp(u, -1);

                int bestMaxDist = INT_MAX;
                int center = -1;
                for(int v : nodes)
                {
                    int maxDist = max(maxDistDown[v], maxDistUp[v]);
                    if(maxDist < bestMaxDist)
                    {
                        bestMaxDist = maxDist;
                        center = v;
                    }
                }

                centers.push_back(center);
                weights.push_back(bestMaxDist);
            }
    }

    sort(weights.begin(), weights.end());
    if(n == 1)
        return weights.end()[-1];
    else if(n == 2)
        return weights.end()[-1] + weights.end()[-2] + lenNew;
    else
        return max(weights.end()[-2] + weights.end()[-3] + lenNew * 2, weights.end()[-1] + weights.end()[-2] + lenNew);
}
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 14148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 14148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 6952 KB Output is correct
2 Correct 36 ms 7100 KB Output is correct
3 Correct 33 ms 7220 KB Output is correct
4 Correct 49 ms 7160 KB Output is correct
5 Correct 32 ms 7088 KB Output is correct
6 Correct 37 ms 7872 KB Output is correct
7 Correct 33 ms 7480 KB Output is correct
8 Correct 34 ms 7112 KB Output is correct
9 Correct 33 ms 7036 KB Output is correct
10 Correct 37 ms 7264 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 5236 KB Output is correct
13 Correct 10 ms 5240 KB Output is correct
14 Correct 10 ms 5248 KB Output is correct
15 Correct 10 ms 5240 KB Output is correct
16 Correct 10 ms 5240 KB Output is correct
17 Correct 10 ms 5240 KB Output is correct
18 Correct 10 ms 5320 KB Output is correct
19 Correct 10 ms 5208 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 424 KB Output is correct
23 Correct 11 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 14148 KB Output isn't correct
2 Halted 0 ms 0 KB -