QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#58539#4648. Average ReplacementAFewSunsAC ✓1656ms11436kbC++2.1kb2022-10-26 19:51:082022-10-26 19:51:09

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-26 19:51:09]
  • 评测
  • 测评结果:AC
  • 用时:1656ms
  • 内存:11436kb
  • [2022-10-26 19:51:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll t,n,m,a[100010],head[100010],cnt=0,d[100010],sum1=0,sum2=0;
bl ck[100010],pd[100010];
db ans[100010];
struct node{
	ll nxt,to;
}e[200020];
void add(ll u,ll v){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
void dfs(ll u){
	ck[u]=1;
	sum1+=a[u]*(d[u]+1);
	sum2+=d[u]+1;
	go(u){
		ll v=e[i].to;
		if(!ck[v]) dfs(v);
	}
}
void dfs2(ll u){
	pd[u]=1;
	ans[u]=1.0*sum1/sum2;
	go(u){
		ll v=e[i].to;
		if(!pd[v]) dfs2(v);
	}
}
int main(){
	t=read();
	while(t--){
		n=read();
		m=read();
		fr(i,1,n) d[i]=head[i]=ck[i]=pd[i]=0;
		cnt=0;
		fr(i,1,n) a[i]=read();
		fr(i,1,m){
			ll u=read(),v=read();
			d[u]++;
			d[v]++;
			add(u,v);
			add(v,u);
		}
		fr(i,1,n){
			if(!ck[i]){
				sum1=sum2=0;
				dfs(i);
				dfs2(i);
			}
		}
		fr(i,1,n) pf("%.6lf\n",ans[i]);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1656ms
memory: 11436kb

input:

100
2 1
1 2
1 2
4 2
1 2 3 4
1 2
3 4
1000 10
12861608 81251431 94636305 97860396 13361461 89521381 9573845 5613423 65053967 22867045 63074541 7376557 68562801 21216095 78889305 34739974 74647393 32495323 15113554 1391235 57948633 91911807 89671183 70279905 48099886 30931849 2289485 44602370 36977326 ...

output:

1.500000
1.500000
1.500000
1.500000
3.500000
3.500000
12861608.000000
81251431.000000
94636305.000000
97860396.000000
13361461.000000
89521381.000000
9573845.000000
5613423.000000
65053967.000000
22867045.000000
63074541.000000
7376557.000000
68562801.000000
21216095.000000
78889305.000000
34739974....

result:

ok 2079006 lines