# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
563599 |
2022-05-17T16:41:01 Z |
Devigo |
Paprike (COI18_paprike) |
C++14 |
|
59 ms |
9348 KB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int siz = 1e5+1;
const int mod = 0;
struct node {
long long u, v;
};
vector<node> el;
vector<long long> par;
vector<long long> rnk;
vector<long long> value;
long long cuts = 0;
long long n, k;
long long get(long long a) {
return par[a] = (par[a] == a) ? a : get(par[a]);
}
void join(long long a, long long b) {
a = get(a); b = get(b);
if(a != b) {
if(rnk[a] == rnk[b]) rnk[a]++;
if(rnk[b] > rnk[a]) swap(a,b);
par[b] = a; value[a] += value[b];
}
}
bool good(long long a, long long b) {
a = get(a); b = get(b);
return value[a] + value[b] <= k;
}
void mincuts() {
for(int i=0; i<n-1; i++) {
long long x = el[i].u; long long y = el[i].v;
if(good(x,y)) {
join(x,y);
}
}
set<long long> s;
for(int i=1; i<=n; i++) {
long long x = get(i);
s.insert(x);
}
cuts = s.size()-1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
value.resize(n+1); par.resize(n+1); rnk.resize(n+1);
for(int i=1; i<=n; i++) {
int x;
cin >> x;
value[i] = x;
}
for(int i=1; i<=n; i++) {
par[i] = i;
}
long long m = n-1;
for(int i=1; i<=m; i++) {
long long a, b;
cin >> a >> b;
el.pb({a,b});
}
mincuts();
cout << cuts << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
9308 KB |
Output is correct |
2 |
Correct |
59 ms |
9308 KB |
Output is correct |
3 |
Correct |
46 ms |
9276 KB |
Output is correct |
4 |
Correct |
48 ms |
9348 KB |
Output is correct |
5 |
Correct |
39 ms |
6940 KB |
Output is correct |
6 |
Correct |
40 ms |
6972 KB |
Output is correct |
7 |
Correct |
38 ms |
7028 KB |
Output is correct |
8 |
Correct |
43 ms |
8452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |