結果

問題 No.1365 [Cherry 1st Tune] Whose Fault?
ユーザー 👑 NachiaNachia
提出日時 2021-02-06 16:42:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 604 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 202,588 KB
実行使用メモリ 5,056 KB
最終ジャッジ日時 2023-09-16 01:50:22
合計ジャッジ時間 22,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 52 ms
4,380 KB
testcase_14 AC 35 ms
4,380 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 30 ms
4,376 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 53 ms
4,376 KB
testcase_20 AC 44 ms
4,376 KB
testcase_21 AC 47 ms
4,376 KB
testcase_22 AC 38 ms
4,376 KB
testcase_23 AC 111 ms
4,380 KB
testcase_24 AC 240 ms
4,380 KB
testcase_25 AC 489 ms
4,624 KB
testcase_26 AC 331 ms
4,488 KB
testcase_27 AC 408 ms
4,380 KB
testcase_28 AC 193 ms
4,380 KB
testcase_29 AC 137 ms
4,380 KB
testcase_30 AC 604 ms
4,604 KB
testcase_31 AC 530 ms
5,056 KB
testcase_32 AC 294 ms
4,604 KB
testcase_33 AC 491 ms
4,380 KB
testcase_34 AC 389 ms
4,380 KB
testcase_35 AC 214 ms
4,384 KB
testcase_36 AC 440 ms
4,900 KB
testcase_37 AC 93 ms
4,380 KB
testcase_38 AC 121 ms
4,456 KB
testcase_39 AC 566 ms
4,548 KB
testcase_40 AC 569 ms
4,544 KB
testcase_41 AC 422 ms
4,620 KB
testcase_42 AC 422 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 253 ms
4,900 KB
testcase_45 AC 361 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

struct dsu{
	vector<int> V;
	dsu(int n){ V.assign(n,-1); }
	int root(int a){ return (V[a]<0)?a:(V[a]=root(V[a])); }
	int unite(int a,int b){ a=root(a); b=root(b); return (a==b)?-1:(V[b]=a); }
};

int N;
long long A[100000];
double P[100000];
int Q;
double ans=0.0;

int main() {
	cin>>N;
	dsu G(N);
	rep(i,N) cin>>A[i];
	rep(i,N){ int b; cin>>b; A[i]-=b; }
	rep(i,N){ int p; cin>>p; P[i]=1.0/p; }
	rep(i,N) ans += A[i]*A[i]/P[i];
	cin>>Q;
	rep(q,Q){
		int u,v,g; cin>>u>>v; u--; v--;
		u=G.root(u); v=G.root(v);
		if(u!=v){
			g=G.unite(u,v);
			ans -= A[u]*A[u]/P[u];
			ans -= A[v]*A[v]/P[v];
			A[g]+=A[u+v-g]; P[g]+=P[u+v-g];
			ans += A[g]*A[g]/P[g];
		}
		printf("%.9f\n",ans);
	}
	return 0;
}
0