Submission #167078

# Submission time Handle Problem Language Result Execution time Memory
167078 2019-12-05T13:09:29 Z hentai_lover Hard route (IZhO17_road) C++14
52 / 100
1219 ms 99320 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define pb push_back
#define fr(i, l, r) for(ll i = l; i <= r; ++ i)
#define rf(i, l, r) for(ll i = l; i >= r; -- i)

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using _set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef int ll;
typedef pair<ll, ll> pll;

const ll oo = ll(1e9) + 10;
const ll N = 5010;

ll f[N][N];
ll n, x, y, now;
vector <ll> g[N];
pll ans;

void dfs(ll x, ll s = 0, ll p = -1){
    f[now][x] = s;
    for(auto i : g[x])
        if(i != p){
            dfs(i, s + 1, x);
            f[now][x] = max(f[now][x], f[now][i]);
        }
}

void dfs2(ll x, ll s = 0, ll pp = -1, ll nw = 0){
    ll m1 = nw, m2 = nw;
    for(auto i : g[x])
        if(i != pp){
            if(m1 <= f[x][i])m2 = m1, m1 = f[x][i];
            else if(m2 <= f[x][i])m2 = f[x][i];
        }
    for(auto i : g[x]){
        if(i != pp){
            if(f[x][i] != m1){
                dfs2(i, s + 1, x, m1);
            }   else{
                dfs2(i, s + 1, x, m2);
            }
        }
    }
    //cout << "x = " << x << " nw = " << nw << " s = " << s << " now = " << now << endl;
    if(g[x].size() == 1 && s != 0){
        if(ans.first < nw * s)ans.first = nw * s, ans.second = 1;
        else if(ans.first == nw * s)ans.first = nw * s, ans.second ++;
    }

}

int main() {
    //ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    fr(i, 2, n){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    fr(i, 1, n){
        now = i;
        dfs(i);
    }

    fr(i, 1, n){
        if(g[i].size() == 1){
            now = i;
            dfs2(i);

        }
    }


    cout << ans.first << ' ' << ans.second / 2 << endl;
}


/*
3 3
1 5 1
2 3
1 3 5
2 3
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 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 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 888 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 888 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 3 ms 888 KB Output is correct
14 Correct 3 ms 888 KB Output is correct
15 Correct 3 ms 892 KB Output is correct
16 Correct 3 ms 888 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 3 ms 888 KB Output is correct
19 Correct 3 ms 888 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 3 ms 888 KB Output is correct
22 Correct 3 ms 864 KB Output is correct
23 Correct 3 ms 888 KB Output is correct
24 Correct 3 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 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 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 888 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 888 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 3 ms 888 KB Output is correct
14 Correct 3 ms 888 KB Output is correct
15 Correct 3 ms 892 KB Output is correct
16 Correct 3 ms 888 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 3 ms 888 KB Output is correct
19 Correct 3 ms 888 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 3 ms 888 KB Output is correct
22 Correct 3 ms 864 KB Output is correct
23 Correct 3 ms 888 KB Output is correct
24 Correct 3 ms 888 KB Output is correct
25 Correct 997 ms 98916 KB Output is correct
26 Correct 948 ms 99104 KB Output is correct
27 Correct 911 ms 99064 KB Output is correct
28 Correct 943 ms 98868 KB Output is correct
29 Correct 951 ms 98936 KB Output is correct
30 Correct 960 ms 98936 KB Output is correct
31 Correct 915 ms 98960 KB Output is correct
32 Correct 938 ms 99064 KB Output is correct
33 Correct 629 ms 99064 KB Output is correct
34 Correct 611 ms 99100 KB Output is correct
35 Correct 635 ms 99064 KB Output is correct
36 Correct 604 ms 99188 KB Output is correct
37 Correct 1219 ms 99320 KB Output is correct
38 Correct 1192 ms 99320 KB Output is correct
39 Correct 1163 ms 98936 KB Output is correct
40 Correct 1083 ms 98660 KB Output is correct
41 Correct 1133 ms 98520 KB Output is correct
42 Correct 1022 ms 98040 KB Output is correct
43 Correct 960 ms 96892 KB Output is correct
44 Correct 946 ms 94840 KB Output is correct
45 Correct 805 ms 88952 KB Output is correct
46 Correct 623 ms 79196 KB Output is correct
47 Correct 984 ms 94900 KB Output is correct
48 Correct 680 ms 98712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 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 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 888 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 888 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 3 ms 888 KB Output is correct
14 Correct 3 ms 888 KB Output is correct
15 Correct 3 ms 892 KB Output is correct
16 Correct 3 ms 888 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 3 ms 888 KB Output is correct
19 Correct 3 ms 888 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 3 ms 888 KB Output is correct
22 Correct 3 ms 864 KB Output is correct
23 Correct 3 ms 888 KB Output is correct
24 Correct 3 ms 888 KB Output is correct
25 Correct 997 ms 98916 KB Output is correct
26 Correct 948 ms 99104 KB Output is correct
27 Correct 911 ms 99064 KB Output is correct
28 Correct 943 ms 98868 KB Output is correct
29 Correct 951 ms 98936 KB Output is correct
30 Correct 960 ms 98936 KB Output is correct
31 Correct 915 ms 98960 KB Output is correct
32 Correct 938 ms 99064 KB Output is correct
33 Correct 629 ms 99064 KB Output is correct
34 Correct 611 ms 99100 KB Output is correct
35 Correct 635 ms 99064 KB Output is correct
36 Correct 604 ms 99188 KB Output is correct
37 Correct 1219 ms 99320 KB Output is correct
38 Correct 1192 ms 99320 KB Output is correct
39 Correct 1163 ms 98936 KB Output is correct
40 Correct 1083 ms 98660 KB Output is correct
41 Correct 1133 ms 98520 KB Output is correct
42 Correct 1022 ms 98040 KB Output is correct
43 Correct 960 ms 96892 KB Output is correct
44 Correct 946 ms 94840 KB Output is correct
45 Correct 805 ms 88952 KB Output is correct
46 Correct 623 ms 79196 KB Output is correct
47 Correct 984 ms 94900 KB Output is correct
48 Correct 680 ms 98712 KB Output is correct
49 Runtime error 773 ms 61612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Halted 0 ms 0 KB -