# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
456393 |
2021-08-06T16:01:19 Z |
dxz05 |
Hard route (IZhO17_road) |
C++14 |
|
33 ms |
47280 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 n;
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 == n - 1 ? 0 : 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 = (edge == g[v].back() ? g[v][sz - 2].first : g[v].back().first);
if (u != p) dfs2(u, v, d + 1, min(h, hh));
}
}
void solve(int TC) {
cin >> n;
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);
}
}
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:64:9: note: in expansion of macro 'debug'
64 | 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:93:13: note: in expansion of macro 'debug'
93 | 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:119:9: note: in expansion of macro 'debug'
119 | debug(test);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
47184 KB |
Output is correct |
2 |
Correct |
30 ms |
47244 KB |
Output is correct |
3 |
Correct |
30 ms |
47276 KB |
Output is correct |
4 |
Correct |
29 ms |
47180 KB |
Output is correct |
5 |
Correct |
29 ms |
47280 KB |
Output is correct |
6 |
Correct |
29 ms |
47180 KB |
Output is correct |
7 |
Incorrect |
33 ms |
47176 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
47184 KB |
Output is correct |
2 |
Correct |
30 ms |
47244 KB |
Output is correct |
3 |
Correct |
30 ms |
47276 KB |
Output is correct |
4 |
Correct |
29 ms |
47180 KB |
Output is correct |
5 |
Correct |
29 ms |
47280 KB |
Output is correct |
6 |
Correct |
29 ms |
47180 KB |
Output is correct |
7 |
Incorrect |
33 ms |
47176 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
47184 KB |
Output is correct |
2 |
Correct |
30 ms |
47244 KB |
Output is correct |
3 |
Correct |
30 ms |
47276 KB |
Output is correct |
4 |
Correct |
29 ms |
47180 KB |
Output is correct |
5 |
Correct |
29 ms |
47280 KB |
Output is correct |
6 |
Correct |
29 ms |
47180 KB |
Output is correct |
7 |
Incorrect |
33 ms |
47176 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |