답안 #531538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531538 2022-03-01T03:07:05 Z Killer2501 Parkovi (COCI22_parkovi) C++14
0 / 110
409 ms 37208 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;
            }
            else
                b[u] = max(b[u], b[v.se]+v.fi);
        }
    }
    if(a[u] >= b[u])b[u] = 0;
}
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;
        m = mid;
        fill_n(vis, n+1, false);
        tong = 0;
        dfs(1);
        if(tong <= k)r = mid-1;
        else l = mid+1;
    }
    tong = 0;
    fill_n(vis, n+1, false);
    m = l;
    dfs(1);
    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:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 321 ms 34356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 409 ms 37208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -