Submission #5771576
Source Code Expand
#include<bits/stdc++.h>
#include <queue>
#include<map>
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(ar) ar.begin(), ar.end()
#define mp make_pair
#define sot(bello) bello.begin(),bello.end()
#define bitc __builtin_popcountl
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define MAXN 100010
#define MOD 1000000007
#define debug(x) cout<<#x<<": "<<x<<endl
#define dbug(x) cout<<#x<<": "<<x<<" "
#define fi first
#define se second
#define arr1d(a,n) cout << #a << " : "; fr(_,1,n) cout << a[_] << ' '; cout << endl;
#define arr1d0(a,n) cout << #a << " : "; rep(_,n) cout << a[_] << ' '; cout << endl;
#define arr2d(a,n,m) cout << #a << " :" << endl; fr(_,1,n) {fr(__,1,m) cout << a[_][__] << ' '; cout << endl;}
#define arr2d0(a,n,m) cout << #a << " :" << endl; rep(_,n) {rep(__,m) cout << a[_][__] << ' '; cout << endl;}
# define INF LLONG_MAX
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
using namespace std;
vector<ll> co(10010);
ll n,sum;
// Dfs search
void dfs(std::vector<ll> v[],ll s,bool visited[],ll &cc,ll ar[])
{
visited[s]=true;
co[s]=ar[cc];
cc--;
for (ll i = 0; i < v[s].size(); ++i)
{
if(!visited[v[s][i]] )
{
dfs(v,v[s][i],visited,cc,ar);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
vector<ll> v[n+1];
rep(i,n-1){
ll a,b;
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
ll c[n];
rep(i,n){
cin>>c[i];
sum+=c[i];
}
sort(c,c+n);
vector<pair<ll,ll> > vec;
fr(i,1,n){
vec.push_back(mp(v[i].size(),i));
}
sort(sot(vec));
ll ind=vec[n-1].second;
bool visited[n+1];
ll cc=n-1;
dfs(v,ind,visited,cc,c);
cout<<sum-c[n-1]<<endl;
fr(i,1,n){
cout<<co[i]<<" ";
}
cout<<endl;
}
Submission Info
| Submission Time |
|
| Task |
D - Maximum Sum of Minimum |
| User |
muneur |
| Language |
C++14 (GCC 5.4.1) |
| Score |
0 |
| Code Size |
2093 Byte |
| Status |
WA |
| Exec Time |
7 ms |
| Memory |
1408 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
WA |
4 ms |
896 KiB |
| 001.txt |
WA |
7 ms |
1408 KiB |
| 002.txt |
WA |
4 ms |
896 KiB |
| 003.txt |
WA |
7 ms |
1408 KiB |
| 004.txt |
WA |
4 ms |
896 KiB |
| 005.txt |
WA |
7 ms |
1408 KiB |
| 006.txt |
WA |
4 ms |
896 KiB |
| 007.txt |
WA |
7 ms |
1408 KiB |
| 008.txt |
WA |
4 ms |
896 KiB |
| 009.txt |
WA |
7 ms |
1408 KiB |
| 010.txt |
WA |
4 ms |
896 KiB |
| 011.txt |
WA |
7 ms |
1408 KiB |
| 012.txt |
WA |
4 ms |
896 KiB |
| 013.txt |
WA |
7 ms |
1408 KiB |
| 014.txt |
WA |
4 ms |
896 KiB |
| 015.txt |
WA |
7 ms |
1408 KiB |
| 016.txt |
WA |
4 ms |
896 KiB |
| 017.txt |
WA |
7 ms |
1408 KiB |
| 018.txt |
WA |
4 ms |
896 KiB |
| 019.txt |
WA |
7 ms |
1408 KiB |
| 020.txt |
WA |
4 ms |
896 KiB |
| 021.txt |
WA |
6 ms |
1408 KiB |
| 022.txt |
WA |
4 ms |
896 KiB |
| 023.txt |
WA |
6 ms |
1408 KiB |
| example0.txt |
AC |
1 ms |
384 KiB |
| example1.txt |
AC |
1 ms |
384 KiB |