Submission #531544

# Submission time Handle Problem Language Result Execution time Memory
531544 2022-03-01T03:23:09 Z Killer2501 Parkovi (COCI22_parkovi) C++14
110 / 110
1394 ms 37700 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+5;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
int n, lab[N], tong, d[N], t, c[N], dp[N], k;
ll ans, m, a[N], b[N];
vector<pii> adj[N];
vector<pll> vi;
string s;
bool vis[N];
void dfs(int u, int p = 0)
{
    b[u] = 0;
    a[u] = -1;
    for(pii v: adj[u])
    {
        if(v.se == p)continue;
        dfs(v.se, u);
        if(a[v.se] != -1)a[u] = max(a[u], a[v.se]-v.fi);
        else
        {
            if(b[v.se]+v.fi > m)
            {
                ++tong;
                vis[v.se] = 1;
                a[u] = max(a[u], m-v.fi);
            }
            else
                b[u] = max(b[u], b[v.se]+v.fi);
        }
    }
    if(a[u] >= b[u])b[u] = 0;
    else a[u] = -1;
}
bool check(ll x)
{
    fill_n(vis, n+1, false);
    m = x;
    tong = 0;
    dfs(1);
    if(a[1] == -1)
    {
        vis[1] = true;
        ++tong;
    }
    return tong <= k;
}
void sol()
{
    cin >> n >> k;
    for(int i = 1; i < n; i ++)
    {
        int x, y, w;
        cin >> x >> y >> w;
        adj[x].pb({w, y});
        adj[y].pb({w, x});
    }
    ll l = 0, r = 1e15, mid;
    while(l <= r)
    {
        mid = (l+r)>>1;
        if(check(mid))r = mid-1;
        else l = mid+1;
    }
    check(l);
    cout << l << '\n';
    for(int i = 1; i <= n; i ++)
    {
        if(vis[i])cout << i <<" ";
        else if(tong < k)
        {
            ++tong;
            cout << i <<" ";
        }
    }

}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}
/*
1234
21
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 31896 KB Output is correct
2 Correct 332 ms 36448 KB Output is correct
3 Correct 309 ms 22092 KB Output is correct
4 Correct 1303 ms 21912 KB Output is correct
5 Correct 1187 ms 21372 KB Output is correct
6 Correct 1212 ms 21504 KB Output is correct
7 Correct 1176 ms 20212 KB Output is correct
8 Correct 1223 ms 21008 KB Output is correct
9 Correct 1242 ms 21308 KB Output is correct
10 Correct 1301 ms 21712 KB Output is correct
11 Correct 873 ms 23256 KB Output is correct
12 Correct 841 ms 22936 KB Output is correct
13 Correct 909 ms 24804 KB Output is correct
14 Correct 820 ms 21644 KB Output is correct
15 Correct 784 ms 21332 KB Output is correct
16 Correct 834 ms 22660 KB Output is correct
17 Correct 805 ms 21940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 33000 KB Output is correct
2 Correct 319 ms 36304 KB Output is correct
3 Correct 314 ms 34680 KB Output is correct
4 Correct 302 ms 34512 KB Output is correct
5 Correct 362 ms 36976 KB Output is correct
6 Correct 369 ms 36676 KB Output is correct
7 Correct 368 ms 37700 KB Output is correct
8 Correct 326 ms 36740 KB Output is correct
9 Correct 344 ms 36572 KB Output is correct
10 Correct 328 ms 35820 KB Output is correct
11 Correct 321 ms 34600 KB Output is correct
12 Correct 423 ms 37316 KB Output is correct
13 Correct 385 ms 37692 KB Output is correct
14 Correct 384 ms 36812 KB Output is correct
15 Correct 315 ms 35068 KB Output is correct
16 Correct 301 ms 33732 KB Output is correct
17 Correct 305 ms 33092 KB Output is correct
18 Correct 319 ms 32592 KB Output is correct
19 Correct 311 ms 32220 KB Output is correct
20 Correct 340 ms 32836 KB Output is correct
21 Correct 329 ms 32244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 314 ms 31896 KB Output is correct
16 Correct 332 ms 36448 KB Output is correct
17 Correct 309 ms 22092 KB Output is correct
18 Correct 1303 ms 21912 KB Output is correct
19 Correct 1187 ms 21372 KB Output is correct
20 Correct 1212 ms 21504 KB Output is correct
21 Correct 1176 ms 20212 KB Output is correct
22 Correct 1223 ms 21008 KB Output is correct
23 Correct 1242 ms 21308 KB Output is correct
24 Correct 1301 ms 21712 KB Output is correct
25 Correct 873 ms 23256 KB Output is correct
26 Correct 841 ms 22936 KB Output is correct
27 Correct 909 ms 24804 KB Output is correct
28 Correct 820 ms 21644 KB Output is correct
29 Correct 784 ms 21332 KB Output is correct
30 Correct 834 ms 22660 KB Output is correct
31 Correct 805 ms 21940 KB Output is correct
32 Correct 335 ms 33000 KB Output is correct
33 Correct 319 ms 36304 KB Output is correct
34 Correct 314 ms 34680 KB Output is correct
35 Correct 302 ms 34512 KB Output is correct
36 Correct 362 ms 36976 KB Output is correct
37 Correct 369 ms 36676 KB Output is correct
38 Correct 368 ms 37700 KB Output is correct
39 Correct 326 ms 36740 KB Output is correct
40 Correct 344 ms 36572 KB Output is correct
41 Correct 328 ms 35820 KB Output is correct
42 Correct 321 ms 34600 KB Output is correct
43 Correct 423 ms 37316 KB Output is correct
44 Correct 385 ms 37692 KB Output is correct
45 Correct 384 ms 36812 KB Output is correct
46 Correct 315 ms 35068 KB Output is correct
47 Correct 301 ms 33732 KB Output is correct
48 Correct 305 ms 33092 KB Output is correct
49 Correct 319 ms 32592 KB Output is correct
50 Correct 311 ms 32220 KB Output is correct
51 Correct 340 ms 32836 KB Output is correct
52 Correct 329 ms 32244 KB Output is correct
53 Correct 1235 ms 17816 KB Output is correct
54 Correct 1283 ms 18304 KB Output is correct
55 Correct 1394 ms 18756 KB Output is correct
56 Correct 1338 ms 18500 KB Output is correct
57 Correct 1318 ms 18848 KB Output is correct
58 Correct 1279 ms 18112 KB Output is correct
59 Correct 1361 ms 19764 KB Output is correct
60 Correct 1357 ms 18812 KB Output is correct
61 Correct 1197 ms 17604 KB Output is correct
62 Correct 1181 ms 17960 KB Output is correct
63 Correct 1348 ms 18784 KB Output is correct
64 Correct 1264 ms 19140 KB Output is correct
65 Correct 1278 ms 18692 KB Output is correct
66 Correct 1266 ms 18424 KB Output is correct
67 Correct 1243 ms 17648 KB Output is correct
68 Correct 1358 ms 19828 KB Output is correct
69 Correct 334 ms 32560 KB Output is correct
70 Correct 304 ms 31704 KB Output is correct
71 Correct 392 ms 33860 KB Output is correct
72 Correct 287 ms 17160 KB Output is correct
73 Correct 293 ms 17636 KB Output is correct
74 Correct 318 ms 18400 KB Output is correct
75 Correct 876 ms 19908 KB Output is correct
76 Correct 919 ms 20304 KB Output is correct
77 Correct 854 ms 19652 KB Output is correct
78 Correct 831 ms 19772 KB Output is correct