#P7390. 「EZEC-6」造树
「EZEC-6」造树
Background
Systematic conclusions can produce mechanical derivations with a “low level of conjecture,” but more problems require inspiration with a “high level of conjecture.”
— command_block, "Pre-exam Tips".
A mindless contestant chooses a thinking problem.
Problem Description
You need to help djy build a tree that satisfies the following conditions:
- It consists of nodes.
- The degree of node is .
Define the value of an edge as . Under the conditions above, you need to maximize the sum of values over all edges.
It is guaranteed that such a tree exists.
Input Format
The first line contains an integer , indicating the method of generating the data.
If :
- The second line contains an integer .
- The third line contains integers, where the -th integer is .
- The fourth line contains integers, where the -th integer is .
If :
A data generator template is given:
int a[10000005],b[10000005];
unsigned seed;
unsigned rnd(unsigned x){
x^=x<<13;
x^=x>>17;
x^=x<<5;
return x;
}
int rad(int x,int y){
seed=rnd(seed);
return seed%(y-x+1)+x;
}
void init_data(){
cin>>n>>seed;
for(int i=1;i<=n;i++)
a[i]=1,b[i]=rad(1,500000);
for(int i=1;i<=n-2;i++)
a[rad(1,n)]++;
}
- The second line contains an integer .
- Then call
init_data(). - The third line contains an integer .
Output Format
Output one integer in a single line, representing the maximum possible sum of values.
0
5
1 2 3 1 1
5 3 1 7 9
42
1
10
114514
249899101316
Hint
This problem uses bundled testing.
- Subtask 0 (10 pts): , .
- Subtask 1 (20 pts): , .
- Subtask 2 (10 pts): , , .
- Subtask 3 (20 pts): , .
- Subtask 4 (20 pts): , .
- Subtask 5 (20 pts): .
For of the testdata, , , , , and .
Translated by ChatGPT 5