Submission #60959061
Source Code Expand
#include "bits/stdc++.h"
#include <chrono>
using namespace std;
#define LL long long
#define mod 998244353ll
#define PI acos(-1.0)
#define set0(ar) memset(ar, 0, sizeof ar)
#define setinf(ar) memset(ar, 126, sizeof ar)
inline LL bigmod(LL p, LL e, LL M) {
LL r = 1;
for (; e > 0; e >>= 1, p = (p * p) % M)
if (e & 1) r = (r * p) % M;
return r;
}
inline LL modinverse(LL a, LL M) { return bigmod(a, M - 2, M); }
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> vc[300001];
int res = 1;
void dfs(int c, int p) {
for(int v: vc[c]) {
if(v == p) continue;
dfs(v, c);
}
vector<int> vp;
for(int v: vc[c]) {
vp.push_back(vc[v].size() - 1);
}
sort(vp.begin(), vp.end());
for(int i = 0; i < vp.size(); i++) {
res = max(res, (int)(vp.size()-i) * (vp[i]+1) + 1);
}
}
void solve() {
int n; cin >> n;
for(int i = 0; i < n-1; i++) {
int x, y; cin >> x >> y;
vc[x].push_back(y);
vc[y].push_back(x);
}
dfs(1, 0);
cout << n-res << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
for (int ts = 1; ts <= T; ts++) {
//cout << "Case " << ts << ": ";
solve();
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Snowflake Tree |
| User | nfssdq |
| Language | C++ 23 (gcc 12.2) |
| Score | 450 |
| Code Size | 1274 Byte |
| Status | AC |
| Exec Time | 97 ms |
| Memory | 44504 KiB |
Compile Error
Main.cpp: In function ‘void dfs(int, int)’:
Main.cpp:34:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
34 | for(int i = 0; i < vp.size(); i++) {
| ~~^~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 2 ms | 3560 KiB |
| 00_sample_02.txt | AC | 2 ms | 3420 KiB |
| 00_sample_03.txt | AC | 2 ms | 3416 KiB |
| 01_random_01.txt | AC | 97 ms | 20232 KiB |
| 01_random_02.txt | AC | 50 ms | 12964 KiB |
| 01_random_03.txt | AC | 94 ms | 20220 KiB |
| 01_random_04.txt | AC | 35 ms | 10384 KiB |
| 01_random_05.txt | AC | 93 ms | 20368 KiB |
| 01_random_06.txt | AC | 10 ms | 5152 KiB |
| 01_random_07.txt | AC | 94 ms | 20096 KiB |
| 01_random_08.txt | AC | 46 ms | 12052 KiB |
| 01_random_09.txt | AC | 92 ms | 20236 KiB |
| 01_random_10.txt | AC | 77 ms | 17476 KiB |
| 01_random_11.txt | AC | 77 ms | 20568 KiB |
| 01_random_12.txt | AC | 73 ms | 17556 KiB |
| 01_random_13.txt | AC | 80 ms | 21056 KiB |
| 01_random_14.txt | AC | 73 ms | 17376 KiB |
| 01_random_15.txt | AC | 90 ms | 20300 KiB |
| 01_random_16.txt | AC | 54 ms | 17640 KiB |
| 01_random_17.txt | AC | 69 ms | 21064 KiB |
| 01_random_18.txt | AC | 71 ms | 18620 KiB |
| 01_random_19.txt | AC | 88 ms | 20172 KiB |
| 01_random_20.txt | AC | 56 ms | 16468 KiB |
| 02_handmade_01.txt | AC | 66 ms | 23564 KiB |
| 02_handmade_02.txt | AC | 71 ms | 21476 KiB |
| 02_handmade_03.txt | AC | 71 ms | 23604 KiB |
| 02_handmade_04.txt | AC | 65 ms | 23732 KiB |
| 02_handmade_05.txt | AC | 93 ms | 44504 KiB |
| 02_handmade_06.txt | AC | 83 ms | 19976 KiB |