結果

問題 No.317 辺の追加
ユーザー 👑 kmjpkmjp
提出日時 2015-12-10 00:38:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,086 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 163,896 KB
実行使用メモリ 10,716 KB
最終ジャッジ日時 2023-10-13 09:50:33
合計ジャッジ時間 5,926 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,620 KB
testcase_01 AC 6 ms
8,768 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 45 ms
9,316 KB
testcase_06 AC 55 ms
9,320 KB
testcase_07 AC 22 ms
9,052 KB
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 21 ms
9,324 KB
testcase_22 AC 14 ms
9,052 KB
testcase_23 AC 14 ms
9,204 KB
testcase_24 AC 32 ms
9,576 KB
testcase_25 AC 25 ms
9,572 KB
testcase_26 AC 26 ms
9,764 KB
testcase_27 AC 22 ms
9,468 KB
testcase_28 AC 14 ms
9,064 KB
testcase_29 AC 8 ms
9,100 KB
testcase_30 AC 75 ms
9,496 KB
testcase_31 AC 66 ms
9,580 KB
testcase_32 AC 67 ms
9,384 KB
testcase_33 AC 67 ms
9,388 KB
testcase_34 AC 66 ms
9,536 KB
testcase_35 AC 68 ms
9,412 KB
testcase_36 AC 67 ms
9,576 KB
testcase_37 AC 68 ms
9,436 KB
testcase_38 AC 74 ms
9,364 KB
testcase_39 AC 67 ms
9,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;
map<int,int> E;
int mi[101010],pre[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		uf(x-1,y-1);
	}
	FOR(i,N) if(uf[i]==i) E[uf.cnt[i]]++;
	FOR(i,N+1) mi[i]=N+100;
	mi[0]=0;
	
	FORR(r,E) {
		if(r.first>=100 || r.second<=10) {
			FOR(j,r.second) {
				for(i=N-r.first+1;i>=0;i--) mi[i+r.first]=min(mi[i+r.first],mi[i]+1);
			}
		}
		else {
			set<pair<int,int>> S[100];
			
			S[0].insert({0,0});
			for(i=j=1;i<=N;i++,j++) {
				pre[i]=mi[i];
				if(j>=r.first) j=0;
				auto it=S[j].begin();
				if(it!=S[j].end()) {
					x=it->first+it->second+(i-it->second)/r.first;
					mi[i]=min(mi[i],x);
				}
				if(pre[i]<N) S[j].insert({pre[i]-i/r.first,i});
				x=i-r.first*r.second;
				if(x>=0) S[j].erase({pre[x]-x/r.first,x});
			}
			
		}
	}
	
	for(i=1;i<=N;i++) {
		if(mi[i]>N) mi[i]=0;
		_P("%d\n",mi[i]-1);
	}
	
}


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