Array construction

4.5

8 votes
Ad-Hoc, Graph, Hard, Approximate, Algorithms, 難しい, Graph Representation
Problem

This is an approximate problem.

You are given 2 numbers n and m and a n×n matrix C. Construct an array a of length n whose sum is equal to m so that the following value ni=1nj=1C[i][j](aiaj)2 is minimized.

Input

The first line contains 2 integers - n,m.

The next (i+1)th(1in) line contains n integers - C[i][1],C[i][2],,C[i][n](C[i][i]=0,C[i][j]=C[j][i]).

There exists three types of test cases and constraints are determined for each type. Please read the "Tests" section below in order to check the constraints.

Output

Output n nonegative integers - a1,a2,,an (0aim).

The array a must satisfy the condition ni=1ai=m.

Scoring

The final score is equal to ni=1nj=1C[i][j](aiaj)2.

Tests

There will 99 tests with three types of generation:

  1. n=32 and m is chosen uniformly from interval [4072,4088], C[i][j](1i<jn) is uniformly chosen from interval [0,220].

  2. n=256 and m is chosen uniformly from interval [3841,4096]. A permutation p is uniformly chosen and a tree is created with vertices (pi,pqi) (1<in) where qi is uniformly chosen in interval [1,i1]. After this C[pi][pqi] (1<in) is uniformly chosen in interval [0,222] while all other values in array C are equal to 0.

  3. n=256 and m is chosen uniformly from interval [3841,4096], C[i][j](1i<jn) is uniformly chosen from interval [0,214].

After the contest, 99 new tests generated with a different seed will be uploaded and the solutions will be evaluated on these tests.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Please note that sample input is not satisfied any constraint above. Array a is equal to (1,1,2) and the score is equal to 2(1(a1a2)2+1(a2a3)2+1(a3a1)2)=2((12)2+(21)2)=4.

Editor Image

?