답안 #170215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170215 2019-12-24T08:57:06 Z andrew Hard route (IZhO17_road) C++17
52 / 100
2000 ms 131012 KB
#include <bits/stdc++.h>

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

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()

using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 1e6;
const ll inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T> void vout(T s){cout << s << endl;exit(0);}

vector <ll> v[MAXN];
bool is_leaf[MAXN];
vector <ll> leaves;
ll Mx[MAXN], kol[MAXN];

ll mx = 0, ans = 0;

void build(ll x, ll pr = 0){
    Mx[x] = 0;
    kol[x] = 1;
    for(auto to : v[x])if(to != pr){
        build(to, x);
        Mx[x] = max(Mx[x], Mx[to] + 1);
        kol[x] += kol[to];
    }
}

void calc(ll x, ll pr = 0, ll Sum = 0, ll deep = 0){
    ll mb = 0;
    if(is_leaf[x] && pr != 0){
        ll t = deep * Sum;
        if(t > mx){
            mx = t;
            ans = 0;
        }
        if(mx == t)ans++;
        return;
    }

    vector <ll> ver, suf, pref;

    for(auto to : v[x])if(to != pr){
        ver.p_b(to);
    }

    ll nn = sz(ver);
    pref.resize(nn);
    suf.resize(nn);

    for(int i = 0; i < nn; i++){
        pref[i] = max(Mx[ver[i]] + 1, (i == 0 ? 0 : pref[i - 1]));
    }

    for(int i = nn - 1; i >= 0; i--){
        suf[i] = max(Mx[ver[i]] + 1, (i == nn - 1 ? 0 : suf[i + 1]));
    }

    for(int i = 0; i < nn; i++){
        calc(ver[i], x, max(Sum, max((i == 0 ? 0 : pref[i - 1]), (i == nn - 1 ? 0 : suf[i + 1]))), deep + 1);

    }

}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL


    ll n;

    cin >> n;

    for(int i = 1; i < n; i++){
        ll a, b;
        cin >> a >> b;
        v[a].p_b(b);
        v[b].p_b(a);
    }

    for(int i = 1; i <= n; i++){
        if(sz(v[i]) == 1){
            is_leaf[i] = 1;
            leaves.p_b(i);
        }
    }

    for(auto root : leaves){
        build(root);
        calc(root);
    }

    cout << mx << " " << ans / 2 << "\n";

    return 0;
}

Compilation message

road.cpp: In function 'void calc(ll, ll, ll, ll)':
road.cpp:47:8: warning: unused variable 'mb' [-Wunused-variable]
     ll mb = 0;
        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 26 ms 26744 KB Output is correct
3 Correct 26 ms 26744 KB Output is correct
4 Correct 26 ms 26872 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 28 ms 26872 KB Output is correct
7 Correct 26 ms 26744 KB Output is correct
8 Correct 27 ms 26744 KB Output is correct
9 Correct 27 ms 26716 KB Output is correct
10 Correct 27 ms 26744 KB Output is correct
11 Correct 27 ms 26744 KB Output is correct
12 Correct 27 ms 26744 KB Output is correct
13 Correct 27 ms 26744 KB Output is correct
14 Correct 28 ms 26744 KB Output is correct
15 Correct 28 ms 26708 KB Output is correct
16 Correct 27 ms 26748 KB Output is correct
17 Correct 27 ms 26744 KB Output is correct
18 Correct 27 ms 26744 KB Output is correct
19 Correct 26 ms 26744 KB Output is correct
20 Correct 27 ms 26744 KB Output is correct
21 Correct 32 ms 26748 KB Output is correct
22 Correct 32 ms 26744 KB Output is correct
23 Correct 28 ms 26788 KB Output is correct
24 Correct 26 ms 26744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 26 ms 26744 KB Output is correct
3 Correct 26 ms 26744 KB Output is correct
4 Correct 26 ms 26872 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 28 ms 26872 KB Output is correct
7 Correct 26 ms 26744 KB Output is correct
8 Correct 27 ms 26744 KB Output is correct
9 Correct 27 ms 26716 KB Output is correct
10 Correct 27 ms 26744 KB Output is correct
11 Correct 27 ms 26744 KB Output is correct
12 Correct 27 ms 26744 KB Output is correct
13 Correct 27 ms 26744 KB Output is correct
14 Correct 28 ms 26744 KB Output is correct
15 Correct 28 ms 26708 KB Output is correct
16 Correct 27 ms 26748 KB Output is correct
17 Correct 27 ms 26744 KB Output is correct
18 Correct 27 ms 26744 KB Output is correct
19 Correct 26 ms 26744 KB Output is correct
20 Correct 27 ms 26744 KB Output is correct
21 Correct 32 ms 26748 KB Output is correct
22 Correct 32 ms 26744 KB Output is correct
23 Correct 28 ms 26788 KB Output is correct
24 Correct 26 ms 26744 KB Output is correct
25 Correct 1032 ms 27808 KB Output is correct
26 Correct 1031 ms 27924 KB Output is correct
27 Correct 1039 ms 27836 KB Output is correct
28 Correct 1037 ms 27816 KB Output is correct
29 Correct 1575 ms 27832 KB Output is correct
30 Correct 1560 ms 27868 KB Output is correct
31 Correct 1561 ms 27896 KB Output is correct
32 Correct 1563 ms 27896 KB Output is correct
33 Correct 41 ms 28024 KB Output is correct
34 Correct 41 ms 28152 KB Output is correct
35 Correct 40 ms 28024 KB Output is correct
36 Correct 40 ms 28152 KB Output is correct
37 Correct 32 ms 28412 KB Output is correct
38 Correct 32 ms 28408 KB Output is correct
39 Correct 34 ms 27640 KB Output is correct
40 Correct 40 ms 27384 KB Output is correct
41 Correct 51 ms 27128 KB Output is correct
42 Correct 80 ms 27128 KB Output is correct
43 Correct 127 ms 27096 KB Output is correct
44 Correct 214 ms 27000 KB Output is correct
45 Correct 427 ms 27128 KB Output is correct
46 Correct 629 ms 27128 KB Output is correct
47 Correct 1303 ms 27216 KB Output is correct
48 Correct 660 ms 27256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 26 ms 26744 KB Output is correct
3 Correct 26 ms 26744 KB Output is correct
4 Correct 26 ms 26872 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 28 ms 26872 KB Output is correct
7 Correct 26 ms 26744 KB Output is correct
8 Correct 27 ms 26744 KB Output is correct
9 Correct 27 ms 26716 KB Output is correct
10 Correct 27 ms 26744 KB Output is correct
11 Correct 27 ms 26744 KB Output is correct
12 Correct 27 ms 26744 KB Output is correct
13 Correct 27 ms 26744 KB Output is correct
14 Correct 28 ms 26744 KB Output is correct
15 Correct 28 ms 26708 KB Output is correct
16 Correct 27 ms 26748 KB Output is correct
17 Correct 27 ms 26744 KB Output is correct
18 Correct 27 ms 26744 KB Output is correct
19 Correct 26 ms 26744 KB Output is correct
20 Correct 27 ms 26744 KB Output is correct
21 Correct 32 ms 26748 KB Output is correct
22 Correct 32 ms 26744 KB Output is correct
23 Correct 28 ms 26788 KB Output is correct
24 Correct 26 ms 26744 KB Output is correct
25 Correct 1032 ms 27808 KB Output is correct
26 Correct 1031 ms 27924 KB Output is correct
27 Correct 1039 ms 27836 KB Output is correct
28 Correct 1037 ms 27816 KB Output is correct
29 Correct 1575 ms 27832 KB Output is correct
30 Correct 1560 ms 27868 KB Output is correct
31 Correct 1561 ms 27896 KB Output is correct
32 Correct 1563 ms 27896 KB Output is correct
33 Correct 41 ms 28024 KB Output is correct
34 Correct 41 ms 28152 KB Output is correct
35 Correct 40 ms 28024 KB Output is correct
36 Correct 40 ms 28152 KB Output is correct
37 Correct 32 ms 28412 KB Output is correct
38 Correct 32 ms 28408 KB Output is correct
39 Correct 34 ms 27640 KB Output is correct
40 Correct 40 ms 27384 KB Output is correct
41 Correct 51 ms 27128 KB Output is correct
42 Correct 80 ms 27128 KB Output is correct
43 Correct 127 ms 27096 KB Output is correct
44 Correct 214 ms 27000 KB Output is correct
45 Correct 427 ms 27128 KB Output is correct
46 Correct 629 ms 27128 KB Output is correct
47 Correct 1303 ms 27216 KB Output is correct
48 Correct 660 ms 27256 KB Output is correct
49 Execution timed out 2037 ms 131012 KB Time limit exceeded
50 Halted 0 ms 0 KB -