Submission #434947

# Submission time Handle Problem Language Result Execution time Memory
434947 2021-06-22T12:51:04 Z alextodoran Dreaming (IOI13_dreaming) C++17
18 / 100
74 ms 13956 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> 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;
                for(int v : nodes)
                {
                    int maxDist = max(maxDistDown[v], maxDistUp[v]);
                    bestMaxDist = min(bestMaxDist, maxDist);
                }

                weights.push_back(bestMaxDist);
            }
    }

    sort(weights.begin(), weights.end());
    if((int)weights.size() == 1)
        return weights.end()[-1];
    else if((int)weights.size() == 2)
        return weights.end()[-1] + weights.end()[-2] + lenNew;
    else
        return max(weights.end()[-1] + weights.end()[-2] + lenNew,
                   weights.end()[-2] + weights.end()[-3] + lenNew * 2);
}
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 13956 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 74 ms 13956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6732 KB Output is correct
2 Correct 39 ms 6732 KB Output is correct
3 Correct 33 ms 6724 KB Output is correct
4 Correct 31 ms 6752 KB Output is correct
5 Correct 37 ms 6732 KB Output is correct
6 Correct 36 ms 7368 KB Output is correct
7 Correct 33 ms 6992 KB Output is correct
8 Correct 29 ms 6644 KB Output is correct
9 Correct 40 ms 6568 KB Output is correct
10 Correct 48 ms 6968 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 4936 KB Output is correct
13 Correct 12 ms 4972 KB Output is correct
14 Correct 14 ms 4936 KB Output is correct
15 Correct 10 ms 4932 KB Output is correct
16 Correct 10 ms 4936 KB Output is correct
17 Correct 11 ms 4952 KB Output is correct
18 Correct 11 ms 4956 KB Output is correct
19 Correct 10 ms 4936 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 10 ms 4936 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 74 ms 13956 KB Output isn't correct
2 Halted 0 ms 0 KB -