| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1059461 | Flan312 | Parkovi (COCI22_parkovi) | C++17 | 321 ms | 35368 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task "CONGVIEN"
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
#define all(s) s.begin(), s.end()
using namespace std;
const ll oo = 1e18;
const int nmax = 2e5 + 2;
int n, k;
bool placed_park[nmax];
vector <pii> adj[nmax];
ll r = 0;
int cnt = 0;
ll dist[nmax], reach[nmax];
void dfs(int u, int par, ll mxDist)
{
dist[u] = oo;
reach[u] = 0;
for (auto &[v, w] : adj[u])
{
if (v == par) continue;
dfs(v, u, mxDist);
if (reach[v] + min(1ll * w, dist[v]) <= mxDist)
{
placed_park[v] = 0;
if (reach[v] + dist[v] > mxDist)
reach[u] = max(reach[u], reach[v] + w);
dist[u] = min(dist[u], dist[v] + w);
}
else
{
placed_park[v] = 1;
++cnt;
dist[u] = min(dist[u], 1ll * w);
}
}
}
bool check(ll mxDist)
{
cnt = 0;
dfs(1, -1, mxDist);
if (reach[1] + dist[1] <= mxDist)
placed_park[1] = 0;
else
{
placed_park[1] = 1;
++cnt;
}
return cnt <= k;
}
int main()
{
if (ifstream(task".inp")) nx
fast
cin >> n >> k;
for (int u, v, w, i = 1; i < n; ++i)
{
cin >> u >> v >> w;
adj[u].eb(v, w);
adj[v].eb(u, w);
r += w;
}
ll l = 0, ans = -1;
while(l <= r)
{
ll mid = l + r >> 1;
if (check(mid))
ans = mid, r = mid - 1;
else l = mid + 1;
}
cout << ans << '\n';
check(ans);
vector <int> res;
for (int i = 1; i <= n; ++i)
if (placed_park[i]) res.eb(i);
for (int i = 1; i <= n; ++i)
if (res.size() < k && !placed_park[i]) res.eb(i);
for (auto &i : res)
cout << i << ' ';
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
