結果

問題 No.416 旅行会社
ユーザー autumn-eelautumn-eel
提出日時 2017-12-15 21:08:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,136 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 177,428 KB
実行使用メモリ 28,764 KB
最終ジャッジ日時 2023-08-21 06:46:39
合計ジャッジ時間 9,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
26,248 KB
testcase_01 AC 5 ms
13,812 KB
testcase_02 AC 4 ms
13,732 KB
testcase_03 AC 5 ms
13,836 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 145 ms
25,596 KB
testcase_11 AC 121 ms
23,140 KB
testcase_12 AC 122 ms
23,032 KB
testcase_13 AC 113 ms
23,976 KB
testcase_14 AC 505 ms
26,656 KB
testcase_15 AC 497 ms
26,600 KB
testcase_16 AC 478 ms
26,384 KB
testcase_17 AC 490 ms
25,396 KB
testcase_18 AC 503 ms
25,900 KB
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
			if(r[j]-l[j]==1)t=r[j];
			v[t].push_back(j);
		}
		init(n);
		for(auto p:se)unite(p.first,p.second);
		for(int j=q;j>=0;j--){
			for(int k:v[j]){
				if(find(k)==find(0))l[k]=j;
				else r[k]=j-1;
			}
			if(j)unite(c[j-1],d[j-1]);
		}
	}
	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)!=find(0))puts("0");
		else printf("%d\n",l[i+1]+1);
	}
}
0