Submission #5731446


Source Code Expand

Copy
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define mo 998244353
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define ms 16
#define endl '\n'

 
using namespace std ;
 
#define N 400005

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

lli ans[10001],ptr=0;
vll c;
vll v[10001];
bool vis[10001];

void dfs(lli q)
{
    vis[q]=1;
    ans[q]=c[ptr];
    ptr++;

    for(auto x:v[q])
    {
        if(!vis[x])
            dfs(x);
    }

}

int main()
{
    
///////////////////////////////////////////
    fastio;

    lli n;
    cin>>n;

    loopl(i,0,n-1)
    {
        lli x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    lli sum=0;
    loopl(i,0,n) 
    {
        lli x;
        cin>>x;
        sum+=x;
        c.pb(x);
    }

    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());

    sum-=c[0];
    dfs(1);

    cout<<sum<<endl;

    loopl(i,1,n+1)
    cout<<ans[i]<<" ";



}

Submission Info

Submission Time
Task D - Maximum Sum of Minimum
User ahskd
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1779 Byte
Status
Exec Time 7 ms
Memory 1536 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0.txt, example1.txt
All 500 / 500 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 4 ms 896 KB
001.txt 7 ms 1280 KB
002.txt 4 ms 896 KB
003.txt 7 ms 1280 KB
004.txt 4 ms 896 KB
005.txt 7 ms 1280 KB
006.txt 4 ms 896 KB
007.txt 7 ms 1280 KB
008.txt 4 ms 896 KB
009.txt 7 ms 1280 KB
010.txt 4 ms 896 KB
011.txt 7 ms 1280 KB
012.txt 4 ms 896 KB
013.txt 7 ms 1152 KB
014.txt 4 ms 896 KB
015.txt 7 ms 1280 KB
016.txt 4 ms 896 KB
017.txt 7 ms 1280 KB
018.txt 4 ms 896 KB
019.txt 7 ms 1280 KB
020.txt 4 ms 1024 KB
021.txt 7 ms 1536 KB
022.txt 4 ms 896 KB
023.txt 6 ms 1280 KB
example0.txt 1 ms 512 KB
example1.txt 1 ms 512 KB