結果

問題 No.1451 集団登校
ユーザー CaliforniumerCaliforniumer
提出日時 2021-03-13 14:38:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 770 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 170,108 KB
実行使用メモリ 812,880 KB
最終ジャッジ日時 2024-04-24 00:46:08
合計ジャッジ時間 4,949 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,320 KB
testcase_01 AC 3 ms
8,320 KB
testcase_02 AC 3 ms
8,320 KB
testcase_03 AC 4 ms
8,320 KB
testcase_04 AC 5 ms
8,320 KB
testcase_05 AC 4 ms
8,448 KB
testcase_06 AC 4 ms
8,448 KB
testcase_07 AC 4 ms
8,320 KB
testcase_08 AC 205 ms
13,480 KB
testcase_09 AC 4 ms
8,192 KB
testcase_10 AC 160 ms
13,620 KB
testcase_11 AC 146 ms
14,080 KB
testcase_12 AC 147 ms
13,056 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll MOD=1e9+7;

int dat[100005];
ll p[100005];
set<int>grp[100005];
void UF_init(int N){
  fill(dat,dat+N,-1);
  fill(p,p+N,1);
  for(int i=0;i<N;i++)grp[i].insert(i);
}
int find(int x){
  return dat[x]<0?x:dat[x]=find(dat[x]);
}
void unite(int x,int y){
  x=find(x);y=find(y);
  if(dat[x]>dat[y])swap(x,y);
  if(dat[x]==dat[y]){
    for(int i:grp[x])(p[i]*=500000004)%=MOD;
    for(int i:grp[y])(p[i]*=500000004)%=MOD;
  }else{
    for(int i:grp[y])p[i]=0;
  }
  for(int i:grp[y])grp[x].insert(i);
  grp[y].clear();
  dat[x]+=dat[y];dat[y]=x;
}

int main(){
  int N,M;cin>>N>>M;
  UF_init(N);
  while(M--){
    int A,B;cin>>A>>B;
    unite(A-1,B-1);
  }
  for(int i=0;i<N;i++)cout<<p[i]<<endl;
}
0