結果

問題 No.1326 ふたりのDominator
ユーザー tailstails
提出日時 2020-12-23 03:28:50
言語 cLay
(20240104-1)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 5,978 ms
コンパイル使用メモリ 187,820 KB
実行使用メモリ 30,248 KB
最終ジャッジ日時 2023-10-24 10:36:19
合計ジャッジ時間 6,762 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,908 KB
testcase_01 AC 5 ms
13,908 KB
testcase_02 AC 5 ms
13,920 KB
testcase_03 AC 5 ms
13,924 KB
testcase_04 AC 5 ms
13,932 KB
testcase_05 AC 5 ms
13,904 KB
testcase_06 AC 4 ms
13,908 KB
testcase_07 AC 5 ms
14,040 KB
testcase_08 AC 5 ms
14,028 KB
testcase_09 AC 5 ms
14,032 KB
testcase_10 AC 6 ms
14,052 KB
testcase_11 AC 5 ms
14,052 KB
testcase_12 AC 54 ms
25,716 KB
testcase_13 AC 58 ms
25,712 KB
testcase_14 AC 53 ms
25,716 KB
testcase_15 AC 54 ms
25,716 KB
testcase_16 AC 54 ms
25,672 KB
testcase_17 AC 61 ms
25,680 KB
testcase_18 AC 87 ms
26,612 KB
testcase_19 AC 60 ms
27,552 KB
testcase_20 AC 55 ms
28,680 KB
testcase_21 AC 56 ms
28,712 KB
testcase_22 AC 74 ms
30,248 KB
testcase_23 AC 39 ms
27,704 KB
testcase_24 AC 58 ms
25,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

vector<int> nev[5d4];
set<int> ens[1d5];
int ena[1d5][2];
unionFind uf;

int nvis[5d4],nla[5d4];

int f1(int ni,int ei){
	if(nvis[ni]==2){
		return 0;
	}
	if(nvis[ni]==1){
		++nla[ni];
		return 1;
	}
	nvis[ni]=1;
	int level=0;
	for(int ej:nev[ni]){
		if(ej!=ei){
			int nj=ni^ena[ej][0]^ena[ej][1];
			nla[ni]=0;
			int l1=f1(nj,ej)-nla[ni];
			level+=l1;
			if(l1){
				uf(ei,ej);
			}
		}
	}
	nvis[ni]=2;
	return level;
}

int ec[1d5],ecn;
int ge[2][2d5];

{
	int @n,@m;
	uf.walloc(m,1);
	rep(i,m){
		int @u,@v;
		--u;
		--v;
		nev[u].push_back(i);
		nev[v].push_back(i);
		ena[i][0]=u;
		ena[i][1]=v;
	}
	f1(0,-1);
	rep(i,m){
		int j=uf(i);
		if(j==i){
			ec[j]=ecn++;
		}
	}
	rep(i,m){
		int j=ec[uf(i)];
		ens[j].insert(ena[i][0]);
		ens[j].insert(ena[i][1]);
	}
	int gen=0;
	rep(i,m){
		for(int j:ens[i]){
			ge[0][gen]=j;
			ge[1][gen]=n+i;
			++gen;
		}
	}
	graph g;
	g.setEdge(n+ecn,gen,ge[0],ge[1]);
	HLD h;
	h.init(g);
	int @q;
	rep(q){
		int @x,@y;
		--x;--y;
		wt(x==y?0:h.dist(x,y)/2-1);
	}
}
0