# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
961140 |
2024-04-11T14:44:42 Z |
Pety |
Parkovi (COCI22_parkovi) |
C++17 |
|
96 ms |
33008 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+2;
using ll = long long;
const int mod = 1e9 + 7;
ll lim;
ll dist1[200002], dist2[200002], cnt, k, n;
bool viz[200002], ok[200002];
vector<pair<int, int>>G[200002];
void dfs (int nod, int par, ll last) {
dist1[nod] = 0;
dist2[nod] = -1;
for (auto [u, x] : G[nod]) {
if (u == par)
continue;
dfs(u, nod, x);
if (ok[u])
dist2[nod] = max(dist2[nod], lim - (x + dist2[u]));
else
dist1[nod] = max(dist1[nod], x + dist1[nod]);
}
if (dist1[nod] <= dist2[nod]) {
ok[nod] = 1;
return;
}
if (dist1[nod] + last > lim) {
ok[nod] = 1;
viz[nod] = 1;
cnt++;
return;
}
ok[nod] = 0;
return;
}
bool solve () {
cnt = 0;
memset(viz, 0, sizeof(viz));
dfs(1, 0, 1e17);
return (cnt <= k);
}
void cb () {
ll st = 0, dr = 10, ans;
while (st <= dr) {
lim = (st + dr) / 2;
if (solve()) {
ans = lim;
dr = lim - 1;
}
else
st = lim +1;
}
cout << ans << "\n";
lim = ans;
}
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 1; i < n; i++) {
int x, y, z;
cin >> x >> y >> z;
G[x].push_back({y, z});
G[y].push_back({x, z});
}
cb();
memset(viz, 0, sizeof(viz));
dfs(1, 0, 1e17);
for (int i = 1; i <= n; i++)
if (viz[i])
cout << i << " ";
return 0;
}
Compilation message
Main.cpp: In function 'void cb()':
Main.cpp:59:7: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
59 | lim = ans;
| ~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
31944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
96 ms |
33008 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |