Problem:
Skyland
Somewhere in the sky, KM  kingdom built
n
floating islands by their highly developed technology.
The islands are numbered from 1 to
n
.
The king of the country, Kita_masa, can choose any non-negative real number as  the altitude for each island, as long as the  sum of the altitudes is greater than or equals to
H
.
For floating  the island
i
to the altitude
h_i
, it  costs
b_i h_i
.
Besides, it  costs
|h_i - h_j|c_{i,j}
for each pair of islands
i
and
j
since there are  communications between  these islands.
Recently, energy prices are rising, so the king, Kita_masa, wants to minimize the sum of the costs.
The king ordered you, a court programmer, to write a program that finds the altitudes of the floating islands  that minimize the cost.
Input
The input contains several test cases.
Each test case starts with a line containing two integers
n
(
1 \leq n \leq 100
) and
H
(
0\leq H \leq 1,000
), separated by a single space.
The next line  contains
n
integers
b_1
,
b_2
,...,
b_n
(
0\leq b_i \leq 1,000
).
Each of the next
n
lines contains
n
integers
c_{i,j}
(
0 \leq c_{i,j} \leq 1,000
).
You may assume
c_{i, i} = 0
and
c_{i, j} = c_{j, i}
.
The last test case is followed by a line containing two zeros.
Output
For each test case, print its case number.
Then print a line containing a space-separated list of the altitudes of  the islands that minimizes the sum of the costs.
If there are several possible solutions, print any of them.
Your answer will be accepted if the altitude of each island is non-negative, sum of the altitudes is greater than
(1-10^{-9})H
, and the cost calculated from your answer has an absolute or relative error less than
10^{-9}
from the optimal solution.
Follow the format of the sample output.
Sample Input
2 1
1 3
0 1
1 0
3 3
1 2 4
0 2 0
2 0 1
0 1 0
0 0
Output for the Sample Input
Case 1:
0.75 0.25
Case 2:
1.5 1.5 0.0

Submitted solutions:

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const double EPS = 1e-8;
const int MOD = 1000000007;



typedef double Weight;
const Weight INF=99999999;
struct Edge{
	int src,dst;
	Weight weight;
	int rev;
	Edge(int f, int t, Weight c,int rev=0):src(f),dst(t),weight(c),rev(rev){}
};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph &G,int s,int t,Weight cap){
	G[s].push_back(Edge(s,t,cap,G[t].size()));
	G[t].push_back(Edge(t,s,0,G[s].size()-1));
}


void bfs(const Graph &G,vector<int> &level,int s){
	level[s]=0;
	queue<int> que;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		REP(i,G[v].size()){
			const Edge &e=G[v][i];
			if(e.weight>1e-8 && level[e.dst] < 0){
				level[e.dst] = level[v] +1;
				que.push(e.dst);
			}
		}
	}
}
Weight dfs(Graph &G,vector<int> &level,vector<int> &iter,int v,int t,Weight flow){
	if(v==t)return flow;
	for(int &i=iter[v];i<(int)G[v].size();i++){
		Edge &e=G[v][i];
		if(e.weight>0&&level[v]<level[e.dst]){
			Weight d=dfs(G,level,iter,e.dst,t,min(flow,e.weight));
			if(d>0){
				e.weight-=d;
				G[e.dst][e.rev].weight+=d;
				return d;
			}
		}
	}
return 0;
}

// Dinic
// O(EV^2)
Weight max_flow(Graph &G,int s,int t){
	Weight flow = 0;
	while(true){
		vector<int> level(G.size(),-1);
		vector<int> iter(G.size(),0);
		bfs(G,level,s);
		if(level[t]<0)break; // もう流せない
		Weight f=0;
		while((f=dfs(G,level,iter,s,t,INF))>0){
			flow+=f;
		}
	}
	return flow;
}


int n, h;
double b[101], c[101][101];

vi solve2(double t){
	Graph g(n+2);
	REP(i, n){
		add_edge(g, n, i,  b[i]);
		add_edge(g, i, n+1, t);
		REP(j, n)if(i!=j){
			add_edge(g, i, j, c[i][j]);
		}
	}
	max_flow(g, n, n+1);
	queue<int> que;
	vi visited(n+2, 1);
	que.push(n);
	visited[n] = visited[n+1] = 0;
	while(!que.empty()){
		int v = que.front(); que.pop();
		FOR(e, g[v])if(e->weight*10 > EPS && visited[e->dst]){
			visited[e->dst] = 0;
			que.push(e->dst);
		}
	}
	return visited;
}

int main(){
	for(int T=1;scanf("%d%d", &n, &h), n;++T){
		REP(i, n) scanf("%lf", &b[i]);
		REP(i, n)REP(j, n) scanf("%lf", &c[i][j]);
		vi ans;
		double l=0.0, r = 2000.0;
		REP(itr, 11){
			double med = (l+r)/2;
			vi res = solve2(med);
			if(accumulate(ALL(res), 0)){
				ans = res;
				r = med;
			}else l = med;
		}
		printf("Case %d:\n", T, l);
		double H = (double)h / accumulate(ALL(ans), 0);
		REP(i, n) printf("%.15f%s", ans[i] ? H : 0.0, i+1==n ? "\n" : " ");
	}
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 1864
final_rank: 1

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const double EPS = 1e-8;
const int MOD = 1000000007;



typedef double Weight;
const Weight INF=99999999;
struct Edge{
	int src,dst;
	Weight weight;
	int rev;
	Edge(int f, int t, Weight c,int rev=0):src(f),dst(t),weight(c),rev(rev){}
};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph &G,int s,int t,Weight cap){
	G[s].push_back(Edge(s,t,cap,G[t].size()));
	G[t].push_back(Edge(t,s,0,G[s].size()-1));
}


void bfs(const Graph &G,vector<int> &level,int s){
	level[s]=0;
	queue<int> que;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		REP(i,G[v].size()){
			const Edge &e=G[v][i];
			if(e.weight>1e-8 && level[e.dst] < 0){
				level[e.dst] = level[v] +1;
				que.push(e.dst);
			}
		}
	}
}
Weight dfs(Graph &G,vector<int> &level,vector<int> &iter,int v,int t,Weight flow){
	if(v==t)return flow;
	for(int &i=iter[v];i<(int)G[v].size();i++){
		Edge &e=G[v][i];
		if(e.weight>0&&level[v]<level[e.dst]){
			Weight d=dfs(G,level,iter,e.dst,t,min(flow,e.weight));
			if(d>0){
				e.weight-=d;
				G[e.dst][e.rev].weight+=d;
				return d;
			}
		}
	}
return 0;
}

// Dinic
// O(EV^2)
Weight max_flow(Graph &G,int s,int t){
	Weight flow = 0;
	while(true){
		vector<int> level(G.size(),-1);
		vector<int> iter(G.size(),0);
		bfs(G,level,s);
		if(level[t]<0)break; // もう流せない
		Weight f=0;
		while((f=dfs(G,level,iter,s,t,INF))>0){
			flow+=f;
		}
	}
	return flow;
}


int n, h;
double b[101], c[101][101];

vi solve2(double t){
	Graph g(n+2);
	REP(i, n){
		add_edge(g, n, i,  b[i]);
		add_edge(g, i, n+1, t);
		REP(j, n)if(i!=j){
			add_edge(g, i, j, c[i][j]);
		}
	}
	max_flow(g, n, n+1);
	queue<int> que;
	vi visited(n+2, 1);
	que.push(n);
	visited[n] = visited[n+1] = 0;
	while(!que.empty()){
		int v = que.front(); que.pop();
		FOR(e, g[v])if(e->weight*10 > EPS && visited[e->dst]){
			visited[e->dst] = 0;
			que.push(e->dst);
		}
	}
	return visited;
}

int main(){
	ios::sync_with_stdio(false);
	for(int T=1;cin >> n >> h, n;++T){
		REP(i, n) cin >> b[i];
		REP(i, n)REP(j, n) cin >> c[i][j];
		vi ans;
		double l=0.0, r = 2000.0;
		REP(itr, 20){
			double med = (l+r)/2;
			vi res = solve2(med);
			if(accumulate(ALL(res), 0)){
				ans = res;
				r = med;
			}else l = med;
		}
		printf("Case %d:\n", T, l);
		int lSl = accumulate(ALL(ans), 0);
		REP(i, n) printf("%.15f%s", ans[i] ? (double)h / lSl : 0.0, i+1==n ? "\n" : " ");
	}
	return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 1908
final_rank: 2

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const double EPS = 1e-8;
const int MOD = 1000000007;



typedef double Weight;
const Weight INF=99999999;
struct Edge{
	int src,dst;
	Weight weight;
	int rev;
	Edge(int f, int t, Weight c,int rev=0):src(f),dst(t),weight(c),rev(rev){}
};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph &G,int s,int t,Weight cap){
	G[s].push_back(Edge(s,t,cap,G[t].size()));
	G[t].push_back(Edge(t,s,0,G[s].size()-1));
}


void bfs(const Graph &G,vector<int> &level,int s){
	level[s]=0;
	queue<int> que;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		REP(i,G[v].size()){
			const Edge &e=G[v][i];
			if(e.weight>1e-8 && level[e.dst] < 0){
				level[e.dst] = level[v] +1;
				que.push(e.dst);
			}
		}
	}
}
Weight dfs(Graph &G,vector<int> &level,vector<int> &iter,int v,int t,Weight flow){
	if(v==t)return flow;
	for(int &i=iter[v];i<(int)G[v].size();i++){
		Edge &e=G[v][i];
		if(e.weight>0&&level[v]<level[e.dst]){
			Weight d=dfs(G,level,iter,e.dst,t,min(flow,e.weight));
			if(d>0){
				e.weight-=d;
				G[e.dst][e.rev].weight+=d;
				return d;
			}
		}
	}
return 0;
}

// Dinic
// O(EV^2)
Weight max_flow(Graph &G,int s,int t){
	Weight flow = 0;
	while(true){
		vector<int> level(G.size(),-1);
		vector<int> iter(G.size(),0);
		bfs(G,level,s);
		if(level[t]<0)break; // もう流せない
		Weight f=0;
		while((f=dfs(G,level,iter,s,t,INF))>0){
			flow+=f;
		}
	}
	return flow;
}


int n, h;
double b[101], c[101][101];

vi solve2(double t){
	Graph g(n+2);
	REP(i, n){
		add_edge(g, n, i,  b[i]);
		add_edge(g, i, n+1, t);
		REP(j, n)if(i!=j){
			add_edge(g, i, j, c[i][j]);
		}
	}
	max_flow(g, n, n+1);
	queue<int> que;
	vi visited(n+2, 1);
	que.push(n);
	visited[n] = visited[n+1] = 0;
	while(!que.empty()){
		int v = que.front(); que.pop();
		FOR(e, g[v])if(e->weight*10 > EPS && visited[e->dst]){
			visited[e->dst] = 0;
			que.push(e->dst);
		}
	}
	return visited;
}

int main(){
	ios::sync_with_stdio(false);
	for(int T=1;cin >> n >> h, n;++T){
		REP(i, n) cin >> b[i];
		REP(i, n)REP(j, n) cin >> c[i][j];
		vi ans;
		double l=0.0, r = 2000.0;
		REP(itr, 40){
			double med = (l+r)/2;
			vi res = solve2(med);
			if(accumulate(ALL(res), 0)){
				ans = res;
				r = med;
			}else l = med;
		}
		printf("Case %d:\n", T, l);
		int lSl = accumulate(ALL(ans), 0);
		REP(i, n) printf("%.15f%s", ans[i] ? (double)h / lSl : 0.0, i+1==n ? "\n" : " ");
	}
	return 0;
}
accuracy: 1
time_ms: 580
memory_kb: 1904
final_rank: 3

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const double EPS = 1e-8;
const int MOD = 1000000007;



typedef double Weight;
const Weight INF=99999999;
struct Edge{
	int src,dst;
	Weight weight;
	int rev;
	Edge(int f, int t, Weight c,int rev=0):src(f),dst(t),weight(c),rev(rev){}
};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph &G,int s,int t,Weight cap){
	G[s].push_back(Edge(s,t,cap,G[t].size()));
	G[t].push_back(Edge(t,s,0,G[s].size()-1));
}


void bfs(const Graph &G,vector<int> &level,int s){
	level[s]=0;
	queue<int> que;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		REP(i,G[v].size()){
			const Edge &e=G[v][i];
			if(e.weight>1e-8 && level[e.dst] < 0){
				level[e.dst] = level[v] +1;
				que.push(e.dst);
			}
		}
	}
}
Weight dfs(Graph &G,vector<int> &level,vector<int> &iter,int v,int t,Weight flow){
	if(v==t)return flow;
	for(int &i=iter[v];i<(int)G[v].size();i++){
		Edge &e=G[v][i];
		if(e.weight>0&&level[v]<level[e.dst]){
			Weight d=dfs(G,level,iter,e.dst,t,min(flow,e.weight));
			if(d>0){
				e.weight-=d;
				G[e.dst][e.rev].weight+=d;
				return d;
			}
		}
	}
return 0;
}

// Dinic
// O(EV^2)
Weight max_flow(Graph &G,int s,int t){
	Weight flow = 0;
	while(true){
		vector<int> level(G.size(),-1);
		vector<int> iter(G.size(),0);
		bfs(G,level,s);
		if(level[t]<0)break; // もう流せない
		Weight f=0;
		while((f=dfs(G,level,iter,s,t,INF))>0){
			flow+=f;
		}
	}
	return flow;
}


int n, h;
double b[101], c[101][101];

vi solve2(double t){
	Graph g(n+2);
	REP(i, n){
		add_edge(g, n, i,  b[i]);
		add_edge(g, i, n+1, t);
		REP(j, n)if(i!=j){
			add_edge(g, i, j, c[i][j]);
		}
	}
	max_flow(g, n, n+1);
	queue<int> que;
	vi visited(n+2, 1);
	que.push(n);
	visited[n] = visited[n+1] = 0;
	while(!que.empty()){
		int v = que.front(); que.pop();
		FOR(e, g[v])if(e->weight*10 > EPS && visited[e->dst]){
			visited[e->dst] = 0;
			que.push(e->dst);
		}
	}
	return visited;
}

int main(){
	ios::sync_with_stdio(false);
	for(int T=1;cin >> n >> h, n;++T){
		REP(i, n) cin >> b[i];
		REP(i, n)REP(j, n) cin >> c[i][j];
		vi ans;
		double l=0.0, r = 2000.0;
		REP(itr, 60){
			double med = (l+r)/2;
			vi res = solve2(med);
			if(accumulate(ALL(res), 0)){
				ans = res;
				r = med;
			}else l = med;
		}
		printf("Case %d:\n", T, l);
		int lSl = accumulate(ALL(ans), 0);
		REP(i, n) printf("%.15f%s", ans[i] ? (double)h / lSl : 0.0, i+1==n ? "\n" : " ");
	}
	return 0;
}
accuracy: 1
time_ms: 880
memory_kb: 1908
final_rank: 4

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const double EPS = 1e-8;
const int MOD = 1000000007;



typedef double Weight;
const Weight INF=99999999;
struct Edge{
	int src,dst;
	Weight weight;
	int rev;
	Edge(int f, int t, Weight c,int rev=0):src(f),dst(t),weight(c),rev(rev){}
};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph &G,int s,int t,Weight cap){
	G[s].push_back(Edge(s,t,cap,G[t].size()));
	G[t].push_back(Edge(t,s,0,G[s].size()-1));
}


void bfs(const Graph &G,vector<int> &level,int s){
	level[s]=0;
	queue<int> que;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		REP(i,G[v].size()){
			const Edge &e=G[v][i];
			if(e.weight>1e-8 && level[e.dst] < 0){
				level[e.dst] = level[v] +1;
				que.push(e.dst);
			}
		}
	}
}
Weight dfs(Graph &G,vector<int> &level,vector<int> &iter,int v,int t,Weight flow){
	if(v==t)return flow;
	for(int &i=iter[v];i<(int)G[v].size();i++){
		Edge &e=G[v][i];
		if(e.weight>0&&level[v]<level[e.dst]){
			Weight d=dfs(G,level,iter,e.dst,t,min(flow,e.weight));
			if(d>0){
				e.weight-=d;
				G[e.dst][e.rev].weight+=d;
				return d;
			}
		}
	}
return 0;
}

// Dinic
// O(EV^2)
Weight max_flow(Graph &G,int s,int t){
	Weight flow = 0;
	while(true){
		vector<int> level(G.size(),-1);
		vector<int> iter(G.size(),0);
		bfs(G,level,s);
		if(level[t]<0)break; // もう流せない
		Weight f=0;
		while((f=dfs(G,level,iter,s,t,INF))>0){
			flow+=f;
		}
	}
	return flow;
}


int n, h;
double b[101], c[101][101];
vi ans;
pair<double, vi> solve(int req, double t){
	Graph g(n+2);
	REP(i, n){
		add_edge(g, n, i,   b[i]);
		add_edge(g, i, n+1, i == req ? 1e8 : t);
		REP(j, n)if(i!=j){
			add_edge(g, i, j, c[i][j]);
		}
	}
	const double cost = max_flow(g, n, n+1) - n * t;
	pair<double, vi> res(cost, vi());
	FOR(e, g[n])if(e->weight < 1e-8) res.second.push_back(e->dst);
	return res;
}

pair<double, vi> solve2(double t){
	Graph g(n+2);
	REP(i, n){
		add_edge(g, n, i,  b[i]);
		add_edge(g, i, n+1, t);
		REP(j, n)if(i!=j){
			add_edge(g, i, j, c[i][j]);
		}
	}
	const double cost1 = max_flow(g, n, n+1) - n * t;
	if(cost1 > EPS) return make_pair(cost1, vi(n+1));
	double cost2 = INF;
	int q = 0;
	queue<int> que;
	vi visited(n+2, 1);
	que.push(n);
	visited[n] = visited[n+1] = 0;
	while(!que.empty()){
		int v = que.front(); que.pop();
		FOR(e, g[v])if(e->weight*100 > EPS && visited[e->dst]){
			visited[e->dst] = 0;
			que.push(e->dst);
		}
	}
	return make_pair(cost1 + !accumulate(ALL(visited), 0), visited);
}

int main(){
	ios::sync_with_stdio(false);
	for(int T=1;cin >> n >> h, n;++T){
		REP(i, n) cin >> b[i];
		REP(i, n)REP(j, n) cin >> c[i][j];
		vi ans;
		double l=0.0, r = 2000.0;
		REP(itr, 60){
			double med = (l+r)/2;
			auto res = solve2(med);
//			cout << itr << ", " << med << ", " << res.first << ", " << res.second << endl;
			if(res.first < 1e-8){
				ans = res.second;
				r = med;
			}else l = med;
		}
//		ans = solve(solve2(l).second, l).second;
		printf("Case %d:\n", T, l);
		int lSl = accumulate(ALL(ans), 0);
		vector<double> qqq(n);
		REP(i, n) qqq[i] = ans[i] ? (double)h / lSl : 0.0;
		double sum = 0;
		REP(i, n) sum += qqq[i] * b[i];
		REP(i, n)REP(j, n) sum += abs(qqq[i] - qqq[j]) * c[i][j];
//		printf("%.10f\n", sum/h);

		REP(i, n) printf("%.15f%s", ans[i] ? (double)h / lSl : 0.0, i+1==n ? "\n" : " ");
	}
	return 0;
}
accuracy: 1
time_ms: 890
memory_kb: 1916
final_rank: 5