警示后人,如果你30~40pts
查看原帖
警示后人,如果你30~40pts
576817
Lyrella楼主2024/11/11 17:06

以我的代码举例,如果你很喜欢压行,也许你会写出下面的代码:

void sol(){
	ii.cnt = 0, rd(m);
	for(int i = 1; i <= m; ++i)rd(a[i]), used[a[i]] = true;
	sort(a + 1, a + 1 + m, cmp); st[top = 1] = a[1];
	for(int i = 2; i <= m; ++i){
		int ff = g.lca(st[top], a[i]);
		if(ff == st[top])st[++top] = a[i];
		else while(true){
			if(dfn[st[top - 1]] <= dfn[ff]){
				ii.add(ff, st[top--], 0);
				if(ff == st[top])st[++top] = a[i];
				else st[++top] = ff, st[++top] = a[i];
				break;
			}
			else ii.add(st[top - 1], st[top--], 0);
		}
	}
	while(--top)ii.add(st[top], st[top + 1], 0);
	wt(ii.dfs(st[1])); pc('\n');
}

然而其中 while 循环里面最后一行不能同时出现 top-1top--,所以会 MLE 和 WA。 应该改成 ```else ii.add(st[top - 1], st[top], 0), --top;

2024/11/11 17:06
加载中...