답안 #167076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167076 2019-12-05T13:03:36 Z hentai_lover Hard route (IZhO17_road) C++14
19 / 100
2000 ms 122104 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], mx[N][3], p[N][3];
ll n, x, y, now;
vector <ll> g[N];
map <ll, ll> mp;

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){
        //cout << "true" << endl;
        mp[nw * s] ++;
    }

}

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);

        }
    }


    pll ans;
    for(auto i : mp){
        ans = i;
    }
    cout << ans.first << ' ' << ans.second / 2 << endl;
}


/*
3 3
1 5 1
2 3
1 3 5
2 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 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 504 KB Output is correct
6 Correct 2 ms 504 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 0 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 888 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 892 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 892 KB Output is correct
23 Correct 3 ms 888 KB Output is correct
24 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 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 504 KB Output is correct
6 Correct 2 ms 504 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 0 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 888 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 892 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 892 KB Output is correct
23 Correct 3 ms 888 KB Output is correct
24 Correct 3 ms 888 KB Output is correct
25 Correct 1148 ms 99028 KB Output is correct
26 Correct 1006 ms 99064 KB Output is correct
27 Correct 998 ms 99192 KB Output is correct
28 Correct 1027 ms 99064 KB Output is correct
29 Execution timed out 2067 ms 122104 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 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 504 KB Output is correct
6 Correct 2 ms 504 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 0 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 888 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 892 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 892 KB Output is correct
23 Correct 3 ms 888 KB Output is correct
24 Correct 3 ms 888 KB Output is correct
25 Correct 1148 ms 99028 KB Output is correct
26 Correct 1006 ms 99064 KB Output is correct
27 Correct 998 ms 99192 KB Output is correct
28 Correct 1027 ms 99064 KB Output is correct
29 Execution timed out 2067 ms 122104 KB Time limit exceeded
30 Halted 0 ms 0 KB -