답안 #1102900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102900 2024-10-19T08:25:17 Z KasymK Hard route (IZhO17_road) C++17
52 / 100
221 ms 1108 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss secox
#define all(v) v.begin(), v.ex()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 5005;
vector<int> adj[N];
int answer, sm, dp[N], odp[N];

void wow(int x, int pr = -1){
    dp[x] = odp[x] = 0;
    tr(it, adj[x]){
        int to = (*it);
        if(to != pr){
            wow(to, x);
            int same = dp[x];
            if(umax(same, dp[to]+1))
                odp[x] = dp[x], dp[x] = same;
            else if(odp[x] < dp[to]+1)
                odp[x] = dp[to]+1;
        }
    }
}

void dfs(int x, int pr, int dis, int mx){
    if(~pr and (int)adj[x].size()==1){
        if(umax(answer, dis*mx))
            sm = 1;
        else if(dis*mx == answer)
            sm++;
        return; 
    }
    tr(it, adj[x]){
        int to = (*it);
        if(to != pr){
            if(dp[to]+1 == dp[x])    
                dfs(to, x, dis+1, max(odp[x],mx));
            else
                dfs(to, x, dis+1, max(dp[x],mx));
        }
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 1; i < n; ++i){
        int a, b;
        scanf("%d%d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vector<int> A;
    for(int i = 1; i <= n; ++i)
        if((int)adj[i].size()==1)
            A.pb(i);
    for(int &to : A){
        wow(to);
        dfs(to, -1, 0, 0);
    }
    printf("%d %d\n", answer, sm>>1);
    return 0;
}

Compilation message

road.cpp: In function 'int main()':
road.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
road.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 508 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 508 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 120 ms 848 KB Output is correct
26 Correct 121 ms 852 KB Output is correct
27 Correct 138 ms 852 KB Output is correct
28 Correct 120 ms 852 KB Output is correct
29 Correct 192 ms 852 KB Output is correct
30 Correct 189 ms 1016 KB Output is correct
31 Correct 198 ms 852 KB Output is correct
32 Correct 186 ms 852 KB Output is correct
33 Correct 4 ms 852 KB Output is correct
34 Correct 4 ms 852 KB Output is correct
35 Correct 3 ms 1092 KB Output is correct
36 Correct 4 ms 1108 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 3 ms 1080 KB Output is correct
39 Correct 4 ms 852 KB Output is correct
40 Correct 4 ms 852 KB Output is correct
41 Correct 8 ms 852 KB Output is correct
42 Correct 11 ms 596 KB Output is correct
43 Correct 17 ms 596 KB Output is correct
44 Correct 31 ms 792 KB Output is correct
45 Correct 54 ms 780 KB Output is correct
46 Correct 75 ms 760 KB Output is correct
47 Correct 182 ms 596 KB Output is correct
48 Correct 221 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 508 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 120 ms 848 KB Output is correct
26 Correct 121 ms 852 KB Output is correct
27 Correct 138 ms 852 KB Output is correct
28 Correct 120 ms 852 KB Output is correct
29 Correct 192 ms 852 KB Output is correct
30 Correct 189 ms 1016 KB Output is correct
31 Correct 198 ms 852 KB Output is correct
32 Correct 186 ms 852 KB Output is correct
33 Correct 4 ms 852 KB Output is correct
34 Correct 4 ms 852 KB Output is correct
35 Correct 3 ms 1092 KB Output is correct
36 Correct 4 ms 1108 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 3 ms 1080 KB Output is correct
39 Correct 4 ms 852 KB Output is correct
40 Correct 4 ms 852 KB Output is correct
41 Correct 8 ms 852 KB Output is correct
42 Correct 11 ms 596 KB Output is correct
43 Correct 17 ms 596 KB Output is correct
44 Correct 31 ms 792 KB Output is correct
45 Correct 54 ms 780 KB Output is correct
46 Correct 75 ms 760 KB Output is correct
47 Correct 182 ms 596 KB Output is correct
48 Correct 221 ms 852 KB Output is correct
49 Runtime error 2 ms 596 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -