結果
| 問題 | 
                            No.1365 [Cherry 1st Tune] Whose Fault?
                             | 
                    
| コンテスト | |
| ユーザー | 
                             moririn2528_c
                         | 
                    
| 提出日時 | 2021-01-23 05:01:29 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,989 bytes | 
| コンパイル時間 | 1,167 ms | 
| コンパイル使用メモリ | 105,880 KB | 
| 実行使用メモリ | 8,896 KB | 
| 最終ジャッジ日時 | 2024-12-29 16:30:25 | 
| 合計ジャッジ時間 | 15,020 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 30 | 
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64,
                 from main.cpp:5:
In member function 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = node; _Alloc = std::allocator<node>]',
    inlined from 'void union_find_tree::init()' at main.cpp:69:18,
    inlined from 'union_find_tree::union_find_tree(int)' at main.cpp:74:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:804:23: warning: '<anonymous>' may be used uninitialized [-Wmaybe-uninitialized]
  804 |       { _M_fill_assign(__n, __val); }
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:70:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/vector.tcc: In constructor 'union_find_tree::union_find_tree(int)':
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/vector.tcc:264:5: note: by argument 3 of type 'const std::vector<node>::value_type&' {aka 'const node&'} to 'void std::vector<_Tp, _Alloc>::_M_fill_assign(std::size_t, const value_type&) [with _Tp = node; _Alloc = std::allocator<node>]' declared here
  264 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
main.cpp:69:26: note: '<anonymous>' declared here
   69 |         v1.assign(n,node());
      |                          ^
            
            ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;
void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
typedef class node{
    typedef long double D;
public:
    D a,b,p;
    node(D _a,D _b,D _p):a(_a),b(_b),p(_p){}
    node(){}
    void connect(node n1){
        b+=n1.b;
        a+=n1.a;
        p=p*n1.p/(p+n1.p);
    }
    D calc(){
        return p*powl(a-b,2);
    }
}node;
class union_find_tree{
private:
    static constexpr int N=100005;
    int n;
    queue<int> q1;
    vector<int> parent;
    vector<int> num;
    typedef long double D;
public:
    vector<node> v1;
    void init(){
        parent.assign(n,-1);
        num.assign(n,1);
        v1.assign(n,node());
    }
    union_find_tree(int n_init){
        assert(n_init>=0);
        n=n_init;
        init();
    }
    union_find_tree(){
        n=N;
        init();
    }
    int check_parent(int x){
        assert(x>=0 && x<n);
        if(parent[x]!=-1){
            q1.push(x);
            return check_parent(parent[x]);
        }
        int a;
        while(!q1.empty()){
            a=q1.front(),q1.pop();
            parent[a]=x;
        }
        return x;
    }
    D connect(int x,int y){
        assert(x>=0 && x<n);
        assert(y>=0 && y<n);
        x=check_parent(x),y=check_parent(y);
        if(x==y)return 0;
        if(num[x]>num[y])swap(x,y);
        parent[x]=y;
        num[y]+=num[x];
        D s=-v1[x].calc()-v1[y].calc();
        v1[y].connect(v1[x]);
        return s+v1[y].calc();
    }
    int size(int pos){
        pos=check_parent(pos);
        return num[pos];
    }
};
int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    cin>>n;
    union_find_tree ua(n);
    for(i=0;i<n;i++)cin>>ua.v1[i].a;
    for(i=0;i<n;i++)cin>>ua.v1[i].b;
    for(i=0;i<n;i++)cin>>ua.v1[i].p;
    long double s=0;
    for(i=0;i<n;i++)s+=ua.v1[i].calc();
    cin>>m;
    cout<<fixed<<setprecision(20);
    for(i=0;i<m;i++){
        cin>>a>>b;
        a--,b--;
        s+=ua.connect(a,b);
        cout<<s<<endl;
    }
}
            
            
            
        
            
moririn2528_c