結果
問題 | No.1365 [Cherry 1st Tune] Whose Fault? |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-22 23:04:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 324 ms / 2,000 ms |
コード長 | 942 bytes |
コンパイル時間 | 2,323 ms |
コンパイル使用メモリ | 195,892 KB |
最終ジャッジ日時 | 2025-01-18 05:35:07 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:21:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:23:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | rep(i,N){ int a; scanf("%d",&a); A[i]=a; } | ~~~~~^~~~~~~~~ main.cpp:24:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | rep(i,N){ int b; scanf("%d",&b); A[i]-=b; } | ~~~~~^~~~~~~~~ main.cpp:25:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | rep(i,N){ int p; scanf("%d",&p); P[i]=1.0/p; } | ~~~~~^~~~~~~~~ main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d",&Q); | ~~~~~^~~~~~~~~ main.cpp:29:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | int u,v; scanf("%d%d",&u,&v); u--; v--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;using LL = long long;using ULL = unsigned long long;#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;LL A[100000];double P[100000];int Q;double ans=0.0;int main() {scanf("%d",&N);dsu G(N);rep(i,N){ int a; scanf("%d",&a); A[i]=a; }rep(i,N){ int b; scanf("%d",&b); A[i]-=b; }rep(i,N){ int p; scanf("%d",&p); P[i]=1.0/p; }rep(i,N) ans += A[i]*A[i]/P[i];scanf("%d",&Q);rep(q,Q){int u,v; scanf("%d%d",&u,&v); u--; v--;u=G.root(u); v=G.root(v);if(u!=v){int 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("%.10f\n",ans);}return 0;}