Submission #93242

# Submission time Handle Problem Language Result Execution time Memory
93242 2019-01-07T10:37:37 Z SamAnd Hard route (IZhO17_road) C++17
19 / 100
2000 ms 55404 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 5003;

int n;
vector<int> a[N];

int ans[N][N];

int d[N], maxd[N];;
void dfs0(int x, int p)
{
    if (x == p)
        d[x] = 0;
    else
        d[x] = d[p] + 1;
    maxd[x] = d[x];
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
            continue;
        dfs0(h, x);
        maxd[x] = max(maxd[x], maxd[h]);
    }
}

void dfs(int x, int p, int dd, int pp)
{
    multiset<int> s;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
            continue;
        s.insert(maxd[h] - d[x]);
    }
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
            continue;
        s.erase(s.find(maxd[h] - d[x]));
        if (s.empty())
            dfs(h, x, dd, pp);
        else
            dfs(h, x, max(dd, *(--s.end())), pp);
        s.insert(maxd[h] - d[x]);
    }
    ans[pp][x] = dd * d[x];
}

int main()
{
    //freopen("input2.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n - 1; ++i)
    {
        int x, y;
        cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    for (int x = 1; x <= n; ++x)
    {
        if (a[x].size() == 1)
        {
            if (x == 6)
                cout << "";
            dfs0(x, x);
            dfs(x, x, 0, x);
        }
    }
    int maxu = -1;
    for (int x = 1; x <= n; ++x)
    {
        if (a[x].size() > 1)
            continue;
        for (int y = 1; y <= n; ++y)
        {
            if (a[y].size() > 1)
                continue;
            maxu = max(maxu, ans[x][y]);
        }
    }
    int q = 0;
    for (int x = 1; x <= n; ++x)
    {
        if (a[x].size() > 1)
            continue;
        for (int y = 1; y <= n; ++y)
        {
            if (a[y].size() > 1 || x == y)
                continue;
            if (ans[x][y] == maxu)
                ++q;
        }
    }
    cout << maxu << ' ' << q / 2 << endl;
    return 0;
}

Compilation message

road.cpp: In function 'void dfs0(int, int)':
road.cpp:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
road.cpp: In function 'void dfs(int, int, int, int)':
road.cpp:31:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
road.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 508 KB Output is correct
24 Correct 4 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 508 KB Output is correct
24 Correct 4 ms 888 KB Output is correct
25 Correct 959 ms 29348 KB Output is correct
26 Correct 993 ms 29416 KB Output is correct
27 Correct 977 ms 29620 KB Output is correct
28 Correct 955 ms 29352 KB Output is correct
29 Correct 1696 ms 55280 KB Output is correct
30 Correct 1675 ms 55404 KB Output is correct
31 Correct 1654 ms 55260 KB Output is correct
32 Correct 1706 ms 55308 KB Output is correct
33 Correct 14 ms 1656 KB Output is correct
34 Correct 14 ms 1656 KB Output is correct
35 Correct 13 ms 1656 KB Output is correct
36 Correct 13 ms 1656 KB Output is correct
37 Correct 8 ms 1528 KB Output is correct
38 Correct 7 ms 1528 KB Output is correct
39 Correct 10 ms 1144 KB Output is correct
40 Correct 14 ms 1144 KB Output is correct
41 Correct 22 ms 1276 KB Output is correct
42 Correct 46 ms 2040 KB Output is correct
43 Correct 87 ms 3320 KB Output is correct
44 Correct 158 ms 5356 KB Output is correct
45 Correct 394 ms 11512 KB Output is correct
46 Correct 679 ms 20432 KB Output is correct
47 Execution timed out 2033 ms 50508 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 508 KB Output is correct
24 Correct 4 ms 888 KB Output is correct
25 Correct 959 ms 29348 KB Output is correct
26 Correct 993 ms 29416 KB Output is correct
27 Correct 977 ms 29620 KB Output is correct
28 Correct 955 ms 29352 KB Output is correct
29 Correct 1696 ms 55280 KB Output is correct
30 Correct 1675 ms 55404 KB Output is correct
31 Correct 1654 ms 55260 KB Output is correct
32 Correct 1706 ms 55308 KB Output is correct
33 Correct 14 ms 1656 KB Output is correct
34 Correct 14 ms 1656 KB Output is correct
35 Correct 13 ms 1656 KB Output is correct
36 Correct 13 ms 1656 KB Output is correct
37 Correct 8 ms 1528 KB Output is correct
38 Correct 7 ms 1528 KB Output is correct
39 Correct 10 ms 1144 KB Output is correct
40 Correct 14 ms 1144 KB Output is correct
41 Correct 22 ms 1276 KB Output is correct
42 Correct 46 ms 2040 KB Output is correct
43 Correct 87 ms 3320 KB Output is correct
44 Correct 158 ms 5356 KB Output is correct
45 Correct 394 ms 11512 KB Output is correct
46 Correct 679 ms 20432 KB Output is correct
47 Execution timed out 2033 ms 50508 KB Time limit exceeded
48 Halted 0 ms 0 KB -