제출 #706795

#제출 시각아이디문제언어결과실행 시간메모리
706795aedmhsn새로운 문제 (POI13_luk)C++17
0 / 100
340 ms22280 KiB
#include <bits/stdc++.h>
using namespace std;
 
 
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a)) 
 
 
#define boost() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);

const int mxN=3e5+5;

vector <vector<int>> adj(mxN);

int dist[mxN];

void dfs(int node, int par){
    for(auto x:adj[node]){
        if(x != par){
            dist[x] = dist[node]+1;
            dfs(x, node);
        }
    }
}

int dfs2(int node, int par, int workers=0){
    if(adj[node].size() - (node != 1) == 0)
        return 0;
    ll temp, ret=0;
    temp = (adj[node].size() - (node != 1) - workers)/(dist[node]+1) + ((adj[node].size()-(node != 1)-workers)%(dist[node]+1) != 0);
    for(auto x:adj[node]){
        if(x != par){
            ret += dfs2(x, node, temp);
        }
    }
    return temp + ret;
}

int main(){

    // amount of workers needed=ceil(amount of children/distance) + answer for each subtree
    // so idea is simple like
    // we will solve each subtree seperately
    // for each subtree answer will be equal to:
    // workers_needed - workers_assigned
    //  1
    // / \
    //2   3
    int n;
    cin >> n;
    for(int i=0; i<n-1; i++){
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1, -1);
    cout << dfs2(1, -1);
}

컴파일 시 표준 에러 (stderr) 메시지

luk.cpp:57:5: warning: multi-line comment [-Wcomment]
   57 |     // / \
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...