結果

問題 No.1451 集団登校
ユーザー 👑 kmjpkmjp
提出日時 2021-03-31 23:36:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 202,976 KB
実行使用メモリ 11,952 KB
最終ジャッジ日時 2023-08-22 04:37:39
合計ジャッジ時間 5,681 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,736 KB
testcase_01 AC 3 ms
5,792 KB
testcase_02 AC 3 ms
5,744 KB
testcase_03 AC 3 ms
5,804 KB
testcase_04 AC 3 ms
5,984 KB
testcase_05 AC 3 ms
5,828 KB
testcase_06 AC 3 ms
5,752 KB
testcase_07 AC 3 ms
5,748 KB
testcase_08 AC 115 ms
11,952 KB
testcase_09 AC 4 ms
5,968 KB
testcase_10 AC 140 ms
9,876 KB
testcase_11 AC 136 ms
9,980 KB
testcase_12 AC 127 ms
9,464 KB
testcase_13 AC 157 ms
10,496 KB
testcase_14 AC 134 ms
9,636 KB
testcase_15 AC 85 ms
8,600 KB
testcase_16 AC 129 ms
9,596 KB
testcase_17 AC 23 ms
6,008 KB
testcase_18 AC 56 ms
7,452 KB
testcase_19 AC 83 ms
8,264 KB
testcase_20 AC 141 ms
9,800 KB
testcase_21 AC 14 ms
5,988 KB
testcase_22 AC 24 ms
6,524 KB
testcase_23 AC 6 ms
5,752 KB
testcase_24 AC 135 ms
9,708 KB
testcase_25 AC 77 ms
8,320 KB
testcase_26 AC 132 ms
9,680 KB
testcase_27 AC 74 ms
7,736 KB
testcase_28 AC 35 ms
7,036 KB
testcase_29 AC 76 ms
8,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
vector<int> G[101010];
int C[101010];
const ll mo=1000000007;
ll ret[101010];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) G[i].push_back(i), C[i]=i, ret[i]=1;
	FOR(i,M) {
		cin>>x>>y;
		x=C[x-1];
		y=C[y-1];
		if(x==y) continue;
		
		if(G[x].size()==G[y].size()) {
			FORR(v,G[y]) {
				G[x].push_back(v);
				C[v]=x;
			}
			FORR(v,G[x]) ret[v]=ret[v]*(mo+1)/2%mo;
		}
		else {
			if(G[x].size()<G[y].size()) swap(x,y);
			FORR(v,G[y]) {
				G[x].push_back(v);
				C[v]=x;
				ret[v]=0;
			}
		}
	}
	FOR(i,N) cout<<ret[i]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0