結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,856 KB
testcase_01 AC 6 ms
8,792 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 44 ms
9,332 KB
testcase_06 AC 54 ms
9,508 KB
testcase_07 AC 21 ms
9,184 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 15 ms
9,172 KB
testcase_23 AC 15 ms
9,056 KB
testcase_24 AC 32 ms
9,852 KB
testcase_25 AC 26 ms
9,848 KB
testcase_26 AC 28 ms
9,960 KB
testcase_27 AC 24 ms
9,588 KB
testcase_28 WA -
testcase_29 AC 8 ms
9,336 KB
testcase_30 WA -
testcase_31 AC 99 ms
9,696 KB
testcase_32 AC 104 ms
9,580 KB
testcase_33 AC 105 ms
9,900 KB
testcase_34 AC 102 ms
9,860 KB
testcase_35 AC 105 ms
9,584 KB
testcase_36 AC 104 ms
9,760 KB
testcase_37 AC 104 ms
9,580 KB
testcase_38 WA -
testcase_39 AC 102 ms
9,692 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<=0) {
			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,i});
				x=i-r.first*r.second;
				if(x>=0) S[j].erase({pre[x]-x,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