結果

問題 No.1451 集団登校
ユーザー chocoruskchocorusk
提出日時 2021-03-31 22:42:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,757 bytes
コンパイル時間 3,560 ms
コンパイル使用メモリ 191,396 KB
実行使用メモリ 15,948 KB
最終ジャッジ日時 2023-08-22 03:26:15
合計ジャッジ時間 9,640 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,204 KB
testcase_01 AC 3 ms
6,136 KB
testcase_02 AC 4 ms
6,164 KB
testcase_03 AC 3 ms
6,180 KB
testcase_04 AC 3 ms
6,136 KB
testcase_05 AC 3 ms
6,428 KB
testcase_06 AC 3 ms
6,512 KB
testcase_07 AC 3 ms
6,160 KB
testcase_08 AC 277 ms
15,948 KB
testcase_09 AC 3 ms
6,420 KB
testcase_10 AC 149 ms
9,628 KB
testcase_11 AC 137 ms
9,680 KB
testcase_12 AC 137 ms
9,300 KB
testcase_13 AC 186 ms
10,664 KB
testcase_14 AC 184 ms
10,012 KB
testcase_15 AC 103 ms
8,640 KB
testcase_16 AC 156 ms
9,908 KB
testcase_17 AC 48 ms
6,360 KB
testcase_18 AC 65 ms
7,976 KB
testcase_19 AC 83 ms
8,352 KB
testcase_20 AC 190 ms
10,284 KB
testcase_21 AC 30 ms
6,280 KB
testcase_22 AC 33 ms
7,064 KB
testcase_23 AC 10 ms
6,164 KB
testcase_24 AC 147 ms
9,688 KB
testcase_25 AC 99 ms
8,460 KB
testcase_26 AC 159 ms
9,948 KB
testcase_27 AC 109 ms
8,088 KB
testcase_28 AC 45 ms
7,212 KB
testcase_29 AC 96 ms
8,612 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>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n, m;
    cin>>n>>m;
    using mint=modint1000000007;
    vector<pair<mint, int>> v[100010];
    int par[100010];
    for(int i=0; i<n; i++) v[i].push_back(make_pair(mint(1), i)), par[i]=i;
    for(int i=0; i<m; i++){
        int a, b;
        cin>>a>>b;
        a--; b--;
        a=par[a], b=par[b];
        if(a==b) continue;
        if(v[a].size()>v[b].size()) swap(a, b);
        if(v[a].size()!=v[b].size()){
            while(!v[a].empty()){
                auto p=v[a].back();
                v[a].pop_back();
                v[b].push_back(make_pair(mint(0), p.second));
                par[p.second]=b;
            }
        }else{
            for(auto &p:v[b]) p.first/=mint(2);
            while(!v[a].empty()){
                auto p=v[a].back();
                v[a].pop_back();
                v[b].push_back(make_pair(p.first/mint(2), p.second));
                par[p.second]=b;
            }
        }
    }
    mint ans[100010];
    for(int i=0; i<n; i++){
        for(auto p:v[i]){
            ans[p.second]=p.first;
        }
    }
    for(int i=0; i<n; i++){
        cout<<ans[i].val()<<endl;
    }
    return 0;
}
0