結果

問題 No.416 旅行会社
ユーザー autumn-eelautumn-eel
提出日時 2017-12-15 21:26:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 560 ms / 4,000 ms
コード長 1,109 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 176,372 KB
実行使用メモリ 28,428 KB
最終ジャッジ日時 2023-08-21 10:13:53
合計ジャッジ時間 8,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
26,212 KB
testcase_01 AC 6 ms
13,700 KB
testcase_02 AC 6 ms
13,792 KB
testcase_03 AC 6 ms
13,800 KB
testcase_04 AC 6 ms
13,788 KB
testcase_05 AC 6 ms
13,784 KB
testcase_06 AC 6 ms
13,768 KB
testcase_07 AC 7 ms
13,748 KB
testcase_08 AC 10 ms
14,060 KB
testcase_09 AC 29 ms
15,008 KB
testcase_10 AC 155 ms
25,692 KB
testcase_11 AC 131 ms
23,124 KB
testcase_12 AC 133 ms
23,368 KB
testcase_13 AC 118 ms
24,208 KB
testcase_14 AC 560 ms
26,600 KB
testcase_15 AC 533 ms
27,008 KB
testcase_16 AC 517 ms
25,208 KB
testcase_17 AC 546 ms
25,568 KB
testcase_18 AC 554 ms
25,744 KB
testcase_19 AC 480 ms
28,428 KB
testcase_20 AC 497 ms
28,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;

int par[100000];

void init(int n){
	rep(i,n)par[i]=i;
}
int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);y=find(y);
	if(x==y)return;
	par[x]=y;
}

int a[200000],b[200000],c[200000],d[200000];
int l[200000],r[200000];
vector<int>v[300000];

int main(){
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	set<P>se;
	rep(i,m){
		scanf("%d%d",&a[i],&b[i]);a[i]--;b[i]--;
		se.insert(P(a[i],b[i]));
	}
	rep(i,q){
		scanf("%d%d",&c[i],&d[i]);c[i]--;d[i]--;
		se.erase(P(c[i],d[i]));
	}
	rep(i,n){
		l[i]=0;r[i]=q;
	}
	rep(i,20){
		rep(j,q+1)v[j].clear();
		rep(j,n){
			int t=(l[j]+r[j])/2;
			v[t].push_back(j);
		}
		init(n);
		for(auto p:se)unite(p.first,p.second);
		for(int j=q-1;j>=0;j--){
			for(int k:v[j]){
				if(find(k)==find(0))l[k]=j+1;
				else r[k]=j;
			}
			if(j)unite(c[j],d[j]);
		}
	}
	init(n);
	rep(i,m)unite(a[i],b[i]);
	rep(i,n-1){
		if(l[i+1]==q)puts("-1");
		else if(find(i+1)!=find(0))puts("0");
		else printf("%d\n",l[i+1]+1);
	}
}
0