結果

問題 No.317 辺の追加
ユーザー TawaraTawara
提出日時 2015-12-12 15:38:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,470 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 86,124 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-10-13 11:46:48
合計ジャッジ時間 9,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 90 ms
4,352 KB
testcase_22 AC 49 ms
4,352 KB
testcase_23 WA -
testcase_24 AC 157 ms
4,408 KB
testcase_25 AC 112 ms
4,596 KB
testcase_26 AC 119 ms
4,372 KB
testcase_27 AC 95 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 13 ms
4,348 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 205 ms
4,348 KB
testcase_33 AC 205 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 206 ms
4,352 KB
testcase_36 AC 205 ms
4,352 KB
testcase_37 AC 206 ms
4,348 KB
testcase_38 WA -
testcase_39 AC 205 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <string> VS;
typedef pair<int,int> PII;
typedef long long LL;
typedef vector <LL> VLL;
typedef unsigned long long ULL;
typedef pair <int, LL> PIL;
typedef vector <PIL> VPIL;

//#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
//#define sort(c) sort((c).begin(),(c).end())

#define range(i,a,b) for(int i=(a); i < (b); i++)
#define rep(i,n) range(i,0,n)

int parent[100001];

int root(int x){
	if (x != parent[x]) parent[x] = root(parent[x]);
	return parent[x];
}
int main(){
	int N,M,C,u,v,c,w;
	map <int,int> conn_comp, comp_num;
	map <int,int> :: iterator mit;
	VI ans;
	cin >> N >> M;
	ans = VI(N+1,N); ans[0] = 0;
	rep(i,N) parent[i] = i;
	rep(i,M){
		cin >> u >> v;
		u = root(u-1); v = root(v-1);
		if (u!=v) parent[u] = v;
	}
	rep(i,N) conn_comp[root(i)]++;
	for (mit=conn_comp.begin();mit!=conn_comp.end();mit++) comp_num[mit->second]++;
	for (mit=comp_num.begin();mit!=comp_num.end();mit++){
		c = 1; w = mit->first; C = mit->second;
		while (c <= C){
			if ((c&C) != 0) for (int i = N; i >= w; i--) ans[i] = min(ans[i],ans[i-w]+c);
			c *= 2; w *= 2;
		}
	}
	rep(i,N) cout << (ans[i+1]==N ? -1 : ans[i+1]-1) << endl;
	return 0;
}
0