Submission #24095526


Source Code Expand

#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define pb push_back
#include<string>
#include<cmath>
#define sz(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#include<string>
#include<cctype>
#define F first
#define S second
#include<queue>
#include <sstream>
#define endl "\n"
#define lli long long int
#define pairs pair<int,int>
#define ld long double
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>
ll pows(ll a,ll n,ll m)
{
	a=a%m;
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1||n==0)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
		return false;
			}	
	}
	return true;
}
const int N=10005;
vector<ll> ar[N];
ll n;
ll vis[N];
ll a[N];
ll ans[N];
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
  cout.tie(0);
  ll TT=clock();
  TT = clock();
cin>>n;
for(ll i=0;i<n-1;i++)
{
	ll x,y;
	cin>>x>>y;
	ar[x].pb(y);
	ar[y].pb(x);
}
for(ll i=0;i<n;i++)
{
	cin>>a[i];
}
sort(a,a+n);
reverse(a,a+n);
queue<ll> q;
q.push(1);
vis[1]=1;
vector<ll> vi;
while(!q.empty())
{
	ll x=q.front();
	q.pop();
	vi.pb(x);
	for(ll child:ar[x])
	{
		if(vis[child]==0)
		{
			q.push(child);
			vis[child]=1;
		}
	}
}
ll sum=0;
for(ll i=0;i<vi.size();i++)
{
	ans[vi[i]]=a[i];
	sum+=a[i];
}
sum-=a[0];
cout<<sum<<endl;
for(ll i=1;i<=n;i++)
{
	cout<<ans[i]<<" ";
}
cerr<<"\n\nTIME: "<<(long double)(clock()-TT)/CLOCKS_PER_SEC<<" sec\n";
    return 0;
}

Submission Info

Submission Time
Task D - Maximum Sum of Minimum
User rohitsoni321
Language C++ (GCC 9.2.1)
Score 500
Code Size 2538 Byte
Status AC
Exec Time 19 ms
Memory 4824 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:147:13: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  147 | for(ll i=0;i<vi.size();i++)
      |            ~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
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 AC 11 ms 4352 KiB
001.txt AC 16 ms 4684 KiB
002.txt AC 12 ms 4420 KiB
003.txt AC 13 ms 4744 KiB
004.txt AC 10 ms 4428 KiB
005.txt AC 9 ms 4664 KiB
006.txt AC 8 ms 4348 KiB
007.txt AC 16 ms 4736 KiB
008.txt AC 8 ms 4352 KiB
009.txt AC 11 ms 4744 KiB
010.txt AC 11 ms 4400 KiB
011.txt AC 13 ms 4664 KiB
012.txt AC 9 ms 4356 KiB
013.txt AC 16 ms 4704 KiB
014.txt AC 10 ms 4392 KiB
015.txt AC 17 ms 4664 KiB
016.txt AC 9 ms 4364 KiB
017.txt AC 13 ms 4712 KiB
018.txt AC 7 ms 4344 KiB
019.txt AC 19 ms 4744 KiB
020.txt AC 11 ms 4324 KiB
021.txt AC 13 ms 4604 KiB
022.txt AC 6 ms 4456 KiB
023.txt AC 9 ms 4824 KiB
example0.txt AC 3 ms 3944 KiB
example1.txt AC 2 ms 3920 KiB