Submission #985179

#TimeUsernameProblemLanguageResultExecution timeMemory
985179shjeongRoad Closures (APIO21_roads)C++17
Compilation error
0 ms0 KiB
#include <vector> #include <iostream> #include <cmath> #include <algorithm> #include <numeric> #include <cstring> #include <vector> #include <string> #include <climits> #include <map> #include <set> #include <stack> #include <queue> #include <bitset> #include <cassert> #include <list> using namespace std; #define all(x) x.begin(), x.end() #define rll(x) x.rbegin(), x.rend() #define comp(x) x.erase(unique(all(x)), x.end()) #define MOD 1000000007 #define MOD2 998244353 #define debug(x) cout << #x<<" is "<<x<<"\n"; #define X first #define Y second #define DEB cout<<"[DEBUG]" #define PAIR(a,b) "("<<a<<", "<<b<<")" #define PRINT1(V) DEB<<#V<<endl; for(auto i : V)DEB<<i<<"\n" #define PRINT2(V) DEB<<#V<<endl; for(auto [a,b] : V)DEB<<PAIR(a,b)<<"\n"; typedef long long ll; typedef __int128_t lll; typedef long double ld; typedef pair<ll,ll> P; typedef pair<ll,P> PP; typedef pair<ld,ll> Pd; ll dp[2020][2]; ll n, k; vector<P> adj[202020]; void dfs(ll cur, ll prv=-1){ priority_queue<ll> pq; for(auto [next,w] : adj[cur])if(prv!=next){ dfs(next,cur); if(dp[next][0] < dp[next][1] + w)pq.push(dp[next][1] + w - dp[next][0]); dp[cur][0] += dp[next][0], dp[cur][1] += dp[next][0]; } vector<ll> v; ll pqsiz = pq.size(); for(int i = 0 ; i < min<ll>(pqsiz, k) ; i++)v.push_back(pq.top()), pq.pop(); for(int i = 0 ; i < min<ll>(v.size(), k) ; i++)dp[cur][0] += v[i]; for(int i = 0 ; i < min<ll>(v.size(), k-1) ; i++)dp[cur][1] += v[i]; } std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { vector<ll> ret(N); n=N; ll S = 0; for(int i = 0 ; i < n-1 ; i++){ S += W[i]; adj[U[i]].push_back({V[i],W[i]}); adj[V[i]].push_back({U[i],W[i]}); } for(int i = 0 ; i < n ; i++){ k=i; memset(dp,0,sizeof(dp)); dfs(0); ret[i] = S - dp[0][0]; } return ret; } int main() { int N; assert(1 == scanf("%d", &N)); std::vector<int> U(N - 1), V(N - 1), W(N - 1); for (int i = 0; i < N - 1; ++i) { assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i])); } std::vector<long long> closure_costs = minimum_closure_costs(N, U, V, W); for (int i = 0; i < static_cast<int>(closure_costs.size()); ++i) { if (i > 0) { printf(" "); } printf("%lld",closure_costs[i]); } printf("\n"); return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccFwOFKb.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccsTCvTc.o:roads.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status