結果

問題 No.317 辺の追加
ユーザー TawaraTawara
提出日時 2015-12-12 14:25:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,615 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 8,948 KB
最終ジャッジ日時 2023-10-13 11:46:01
合計ジャッジ時間 5,030 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,948 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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 Pre[100002];
int ans[100001];

int root(int x){
	if (x != parent[x]) x = root(parent[x]);
	return parent[x];
}
int solve(int n, int x){
	if (x <= n) return x;
	if (ans[x] == -1 && ans[x-n] != -1) ans[x] = ans[x-n] + 1;
	Pre[x] = solve(n,Pre[x]);
	return ans[x] == -1 ? x : Pre[x];
}
int main(){
	int N,M,C,u,v,n,tmp_max;
	map <int,int> conn_comp;
	map <int,int> :: iterator it;
	VI comp_num;
	cin >> N >> M;
	rep(i,N+2) Pre[i]=i-1;
	rep(i,N){ans[i+1] = -1; 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)] += 1;
	for (it=conn_comp.begin();it!=conn_comp.end();it++) comp_num.push_back(it->second);
	sort(comp_num.begin(),comp_num.end(),greater<int>());
	C = comp_num.size();
	tmp_max = 0;
	rep(i,C){
		n = comp_num[i];
		tmp_max += n;
		solve(n,tmp_max+1);
		ans[n] = 0;
	}
	rep(i,N) cout << ans[i+1] << endl;
	return 0;
}
0