Submission #456396

# Submission time Handle Problem Language Result Execution time Memory
456396 2021-08-06T16:12:27 Z dxz05 Hard route (IZhO17_road) C++14
0 / 100
28 ms 47236 KB
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e6 + 3e2;
const int M = 5055;

vector<pair<int, int>> g[N];

void dfs(int v, int p, int d, int &mx){
    mx = max(mx, d);
    for (auto edge : g[v]){
        int u = edge.second;
        if (u != p) dfs(u, v, d + 1, mx);
    }
}

int get(int v, int a, int b){
    int sz = g[v].size();
    for (int i = sz - 1; i >= 0; i--){
        if (g[v][i].second != a && g[v][i].second != b) return g[v][i].first;
    }
    return 0;
}

int ans = -1, cnt = 0;
void dfs2(int v, int p, int d, int h){
    int sz = g[v].size();
    if (sz == 1){
        int cost = d * h;
        if (cost > ans){
            ans = cost;
            cnt = 1;
        } else if (cost == ans) cnt++;
        debug(v, cost, d, h);
        return;
    }

    for (auto edge : g[v]){
        int u = edge.second, hh = get(v, u, p);
        if (u != p) dfs2(u, v, d + 1, min(h, hh));
    }
}

void solve(int TC) {
    int n;
    cin >> n;

    if (n == 2){
        cout << 0 << ' ' << 1 << endl;
        return;
    }

    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(0, v);
        g[v].emplace_back(0, u);
    }

    for (int i = 1; i <= n; i++){
        for (auto &edge : g[i]){
            dfs(edge.second, i, 1, edge.first);
        }
        sort(all(g[i]));
    }

    for (int i = 1; i <= n; i++){
        if (g[i].size() == 1){
            debug(i);
            dfs2(g[i][0].second, i, 1, n);
        }
    }

    assert(cnt % 2 == 0);

    cout << ans << ' ' << cnt / 2 << endl;

}

int main() {
    startTime = clock();
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    bool llololcal = false;
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    llololcal = true;
#endif

    int TC = 1;
    //cin >> TC;

    for (int test = 1; test <= TC; test++) {
        debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}

Compilation message

road.cpp: In function 'void dfs2(int, int, int, int)':
road.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
road.cpp:70:9: note: in expansion of macro 'debug'
   70 |         debug(v, cost, d, h);
      |         ^~~~~
road.cpp: In function 'void solve(int)':
road.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
road.cpp:105:13: note: in expansion of macro 'debug'
  105 |             debug(i);
      |             ^~~~~
road.cpp: In function 'int main()':
road.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
road.cpp:133:9: note: in expansion of macro 'debug'
  133 |         debug(test);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47236 KB Output is correct
2 Correct 28 ms 47180 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47192 KB Output is correct
5 Correct 28 ms 47200 KB Output is correct
6 Correct 28 ms 47184 KB Output is correct
7 Incorrect 28 ms 47232 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47236 KB Output is correct
2 Correct 28 ms 47180 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47192 KB Output is correct
5 Correct 28 ms 47200 KB Output is correct
6 Correct 28 ms 47184 KB Output is correct
7 Incorrect 28 ms 47232 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47236 KB Output is correct
2 Correct 28 ms 47180 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47192 KB Output is correct
5 Correct 28 ms 47200 KB Output is correct
6 Correct 28 ms 47184 KB Output is correct
7 Incorrect 28 ms 47232 KB Output isn't correct
8 Halted 0 ms 0 KB -