結果

問題 No.1326 ふたりのDominator
ユーザー tailstails
提出日時 2020-12-23 12:37:55
言語 cLay
(20240104-1)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 4,034 ms
コンパイル使用メモリ 190,048 KB
実行使用メモリ 29,932 KB
最終ジャッジ日時 2023-10-24 10:38:43
合計ジャッジ時間 6,287 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,856 KB
testcase_01 AC 3 ms
11,856 KB
testcase_02 AC 4 ms
11,868 KB
testcase_03 AC 4 ms
11,872 KB
testcase_04 AC 4 ms
11,884 KB
testcase_05 AC 4 ms
11,856 KB
testcase_06 AC 3 ms
11,856 KB
testcase_07 AC 4 ms
12,004 KB
testcase_08 AC 4 ms
12,000 KB
testcase_09 AC 4 ms
11,988 KB
testcase_10 AC 4 ms
12,028 KB
testcase_11 AC 4 ms
12,032 KB
testcase_12 AC 53 ms
25,444 KB
testcase_13 AC 53 ms
25,444 KB
testcase_14 AC 53 ms
25,444 KB
testcase_15 AC 52 ms
25,444 KB
testcase_16 AC 53 ms
25,180 KB
testcase_17 AC 60 ms
24,124 KB
testcase_18 AC 82 ms
24,468 KB
testcase_19 AC 57 ms
25,408 KB
testcase_20 AC 53 ms
28,348 KB
testcase_21 AC 57 ms
28,348 KB
testcase_22 AC 68 ms
29,932 KB
testcase_23 AC 38 ms
25,572 KB
testcase_24 AC 54 ms
25,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int f1(int ni,int ei){
	if(nvis[ni]){
		return nvis[ni]>0&&++nvis[ni];
	}
	int level=0;
	for(int ej:nev[ni]){
		if(ej!=ei){
			int nj=ni^ena[ej][0]^ena[ej][1];
			nvis[ni]=1;
			int l1=f1(nj,ej)-(nvis[ni]-1);
			level+=l1;
			if(l1){
				uf(ei,ej);
			}
		}
	}
	nvis[ni]=-1;
	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++;
		}
	}
	vector<set<int>> ens(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,ecn){
		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