結果

問題 No.828 全方位神童数
ユーザー chocoruskchocorusk
提出日時 2019-05-03 22:10:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 1,671 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 99,380 KB
実行使用メモリ 48,656 KB
最終ジャッジ日時 2023-08-30 06:10:10
合計ジャッジ時間 9,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
27,980 KB
testcase_01 AC 10 ms
27,924 KB
testcase_02 AC 10 ms
27,988 KB
testcase_03 AC 22 ms
28,748 KB
testcase_04 AC 13 ms
28,316 KB
testcase_05 AC 21 ms
28,672 KB
testcase_06 AC 12 ms
28,148 KB
testcase_07 AC 11 ms
28,124 KB
testcase_08 AC 12 ms
28,200 KB
testcase_09 AC 11 ms
28,008 KB
testcase_10 AC 17 ms
28,436 KB
testcase_11 AC 11 ms
28,304 KB
testcase_12 AC 18 ms
28,512 KB
testcase_13 AC 114 ms
35,400 KB
testcase_14 AC 240 ms
43,116 KB
testcase_15 AC 85 ms
33,980 KB
testcase_16 AC 117 ms
35,652 KB
testcase_17 AC 93 ms
34,508 KB
testcase_18 AC 169 ms
37,960 KB
testcase_19 AC 301 ms
45,504 KB
testcase_20 AC 200 ms
39,516 KB
testcase_21 AC 259 ms
43,924 KB
testcase_22 AC 61 ms
32,872 KB
testcase_23 AC 25 ms
30,952 KB
testcase_24 AC 162 ms
37,348 KB
testcase_25 AC 65 ms
33,032 KB
testcase_26 AC 305 ms
44,896 KB
testcase_27 AC 257 ms
43,132 KB
testcase_28 AC 304 ms
45,036 KB
testcase_29 AC 288 ms
44,364 KB
testcase_30 AC 166 ms
37,260 KB
testcase_31 AC 158 ms
37,244 KB
testcase_32 AC 307 ms
44,844 KB
testcase_33 AC 339 ms
45,924 KB
testcase_34 AC 271 ms
43,252 KB
testcase_35 AC 172 ms
37,836 KB
testcase_36 AC 216 ms
39,480 KB
testcase_37 AC 138 ms
36,408 KB
testcase_38 AC 190 ms
38,824 KB
testcase_39 AC 307 ms
45,032 KB
testcase_40 AC 135 ms
36,364 KB
testcase_41 AC 113 ms
35,252 KB
testcase_42 AC 339 ms
46,224 KB
testcase_43 AC 191 ms
48,656 KB
testcase_44 AC 80 ms
36,504 KB
testcase_45 AC 116 ms
39,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int sz[600010];
int par[600010];
int rk[600010];
vector<int> gu[600010];
vector<int> g[200010];
ll c[600010];
int n;
int n0;
int num[600010];
void init(int n){
	for(int i=0; i<n; i++){
		par[i]=i;
        rk[i]=0;
        num[i]=i;
	}
}
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
    gu[n0].push_back(num[x]);
    gu[n0].push_back(num[y]);
	if(rk[x]<rk[y]){
		par[x]=y;
        num[y]=n0;
	}else{
		par[y]=x;
        num[x]=n0;
		if(rk[x]==rk[y]) rk[x]++;
	}
    n0++;
}
void add(int x){
    c[num[find(x)]]++;
}
ll r[200010];
void dfs(int x){
    for(auto y:gu[x]){
        c[y]+=c[x];
        dfs(y);
    }
}
int main()
{
    int n; cin>>n; n0=n;
    for(int i=0; i<n; i++) cin>>r[i];
    for(int i=0; i<n-1; i++){
        int u, v; cin>>u>>v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(n);
    for(int i=0; i<n; i++){
        for(auto y:g[i]){
            if(y<i) unite(y, i);
        }
        add(i);
    }
    dfs(n0-1);
    ll ans=1;
    for(int i=0; i<n; i++){
        ans*=(r[i]+c[i]);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0