4300 2023. 03. 22 14:51:00 horvathabel Útadó cpp17 Wrong answer 0/50 800ms 8924 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<ll> g[50001];
vector<ll>c(50001);
vector<pair<ll,int>> db ; 
ll dfs(int x){
	if (c[x]==0){
		db[x]={1,x};
		return db[x].first;
	} 
	else{
		for (int edge:g[x]){
			db[x].first+=dfs(edge);
			db[x].second=x; 
		}
	}
	return (db[x].first);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;

vector<int> p;
p.resize(n+1);
for (int i=1;i<n;i++)
{
ll x,y;
cin>>x>>y;
db.assign(n+1, {1,0}); 
c[x]++; 
p[y]=x;
g[x].push_back(y);

}
vector<ll> arak;
for (int i=1; i<n;i++){
	ll x;
	cin>>x; 
	x=x%32609;
	arak.push_back(x);
}

dfs(1);
for (int i=1; i<=n;i++) db[i].first=db[i].first*(n-db[i].first)%32609;
sort(db.begin(), db.end());
sort(arak.begin(), arak.end());
ll ans=0; 
vector<pair<pair<ll, ll>,ll>> cnt; 
for (int i=2; i<=n;i++){
	ans+=db[i].first*arak[i-2]*2;
	ans=ans%32609;
	cnt.push_back({{db[i].second, p[db[i].second]},arak[i-2]});
}
cout<<ans<<endl; 
for (auto x: cnt) cout<<x.first.second<<" "<<x.first.first<<" "<<x.second<<endl; 

}
Subtask Sum Test Verdict Time Memory
base 0/50
1 Accepted 0/0 4ms 4808 KiB
2 Wrong answer 0/0 472ms 8924 KiB
3 Wrong answer 0/2 4ms 5072 KiB
4 Wrong answer 0/2 4ms 5372 KiB
5 Wrong answer 0/2 4ms 5332 KiB
6 Wrong answer 0/2 4ms 5328 KiB
7 Wrong answer 0/2 4ms 5584 KiB
8 Time limit exceeded 0/8 731ms 5092 KiB
9 Wrong answer 0/2 6ms 6364 KiB
10 Wrong answer 0/2 7ms 6456 KiB
11 Wrong answer 0/2 8ms 6456 KiB
12 Wrong answer 0/2 8ms 6600 KiB
13 Wrong answer 0/2 7ms 6620 KiB
14 Time limit exceeded 0/2 800ms 5360 KiB
15 Time limit exceeded 0/2 773ms 5528 KiB
16 Time limit exceeded 0/2 741ms 5640 KiB
17 Time limit exceeded 0/2 758ms 5628 KiB
18 Time limit exceeded 0/2 765ms 5736 KiB
19 Time limit exceeded 0/2 773ms 5800 KiB
20 Time limit exceeded 0/2 762ms 6020 KiB
21 Time limit exceeded 0/2 754ms 6140 KiB
22 Time limit exceeded 0/2 769ms 6260 KiB
23 Time limit exceeded 0/2 745ms 6100 KiB
24 Time limit exceeded 0/2 757ms 6172 KiB