QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287700#1256. Delete Two Vertices AgainDualqwqWA 5ms48780kbC++203.8kb2023-12-20 21:49:462023-12-20 21:49:47

Judging History

你现在查看的是最新测评结果

  • [2023-12-20 21:49:47]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:48780kb
  • [2023-12-20 21:49:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5,M = 6e5 + 5,Lg = 19;
int n,m;
int fir[N],nxt[M],to[M],ect = 1;
inline void addedge(int u1,int v1) {
	nxt[++ect] = fir[u1];fir[u1] = ect;to[ect] = v1;
}

int U[M],V[M];
vector<int> par[N],G[N];
bool vst[N];
int dep[N];

const int Sz = M << 5;
int rt[N],lc[Sz],rc[Sz],sum[Sz],tot = 0;
void insert(int &k,int l,int r,int pos,int v) {
	if(!k) k = ++tot;
	if(l == r) { sum[k] += v;return;}
	int mid = l + r >> 1;
	if(pos <= mid) insert(lc[k],l,mid,pos,v);
	else insert(rc[k],mid + 1,r,pos,v);
	sum[k] = sum[lc[k]] + sum[rc[k]];
}
int Merge(int x,int y,int l,int r) {
	if(!x || !y) return x + y;
	int p = ++tot,mid = l + r >> 1;
	sum[p] = sum[x] + sum[y];
	if(l == r) return p;
	// sum[p] = sum[x] + sum[y];
	lc[p] = Merge(lc[x],lc[y],l,mid);
	rc[p] = Merge(rc[x],rc[y],mid + 1,r);
	// sum[p] = sum[lc[p]] + sum[rc[p]];
	return p;
}
int Query(int k,int l,int r,int x,int y) {
	if(!k || x > y) return 0;
	if(x <= l && r <= y) return sum[k];
	int mid = l + r >> 1;
	if(y <= mid) return Query(lc[k],l,mid,x,y);
	else if(x > mid) return Query(rc[k],mid + 1,r,x,y);
	else return Query(lc[k],l,mid,x,y) + Query(rc[k],mid + 1,r,x,y);
}
int anc[Lg][N];
int dfn[N],sze[N];
inline bool isanc(int x,int y) { return dfn[x] <= dfn[y] && dfn[y] < dfn[x] + sze[x];}
void dfs(int x) {
	// printf("dep[%d]=%d\n",x,dep[x]);
	vst[x] = true;sze[x] = 1;//printf("anc[0][%d]=%d,%d\n",x,anc[0][x],dep[x]);
	for(int i = 1;i < Lg;i++) anc[i][x] = anc[i - 1][anc[i - 1][x]];
	// for(auto y : par[x])
	// 	if(vst[y]) insert(rt[x],1,n,dep[y],1),printf("path:%d,%d\n",x,y);
	dfn[x] = ++dfn[0];
	for(int i = fir[x],y;y = to[i],i;i = nxt[i])
		if(!vst[y]) {

			G[x].push_back(y);
			anc[0][y] = x;
			dep[y] = dep[x] + 1;
			dfs(y);sze[x] += sze[y];
			// rt[x] = Merge(rt[x],rt[y]);
			// printf("%d->%d\n",x,y);
		}
}
inline int Qsub(int x,int lim) {
	int res = 0;
	for(int i = 1;i <= n;i++)
		if(isanc(x,i))
			for(auto j : par[i])
				if(dep[j] <= lim) ++res;
	return res;
}
void dfs1(int x) {	
	for(auto y : par[x]) if(dep[y] < dep[x]) insert(rt[x],1,n,dep[y],1);

	for(auto y : G[x]) dfs1(y),rt[x] = Merge(rt[x],rt[y],1,n);
}
inline int jump(int x,int y) {
	for(int i = Lg - 1;i >= 0;i--)
		if(dep[anc[i][x]] > dep[y]) x = anc[i][x];
	return x;
}
inline bool Ask(int u,int v) {
	if(dep[u] > dep[v]) swap(u,v);
	int pp = jump(v,u);
	// printf("jp:%d,%d,%d\n",u,v,pp);
	if(u != 1) {
		for(auto t : G[u]) {
			// printf("t:%d,%d,%d\n",t,Query(rt[t],1,n,1,dep[u] - 1),Qsub(t,dep[u] - 1));
			if(t != pp && !Query(rt[t],1,n,1,dep[u] - 1)) return false;
		}
		
	}
	else {
		if(G[u].size() > 2) return false;
		if(G[u].size() == 2 && (pp != v || G[v].size())) return false;
	}
	// if(u == 4 && v == 2) {
		// puts("d1");
		// printf("v1,v2:%d,%d,%d,%d,%d,%d\n",pp,v,Query(rt[pp],1,n,1,dep[u] - 1),Query(rt[v],1,n,1,dep[u] - 1),Qsub(pp,dep[u] - 1),Qsub(v,dep[u] - 1));
	// }
	if(pp != v && sze[pp] != 1 && u != 1 && !(Query(rt[pp],1,n,1,dep[u] - 1) - Query(rt[v],1,n,1,dep[u] - 1))) return false;
	// if(u == 4 && v == 2) puts("d2");

	for(auto t : G[v])
		if(sze[t] != n - 2 && !Query(rt[t],1,n,1,dep[v] - 1)) return false;
	return true;
}
int main() {
	cin >> n >> m;
	for(int i = 1;i <= m;i++) {
		cin >> U[i] >> V[i],addedge(U[i],V[i]),addedge(V[i],U[i]);
		par[U[i]].push_back(V[i]);
		par[V[i]].push_back(U[i]);
	}
	dep[1] = 1;dfs(1);dfs1(1);
	// Ask(4,2);
	// cout << "===========" << endl;
	for(int i = 1;i <= m;i++)
		if(Ask(U[i],V[i])) putchar('1'); else putchar('0');
	return 0;
}
/*
10 39
1 2
1 3
1 5
1 6
1 7
1 8
1 9
1 10
2 3
2 4
2 5
2 6
2 9
2 10
3 5
3 6
3 7
3 8
3 10
4 5
4 6
4 7
4 9
4 10
5 6
5 7
5 8
5 9
5 10
6 7
6 8
6 9
6 10
7 8
7 9
7 10
8 9
8 10
9 10
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 48748kb

input:

4 4
1 2
2 3
3 1
4 1

output:

0101

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #2:

score: 0
Accepted
time: 3ms
memory: 48720kb

input:

3 3
1 2
2 3
3 1

output:

111

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #3:

score: 0
Accepted
time: 5ms
memory: 48760kb

input:

3 2
1 2
2 3

output:

11

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #4:

score: 0
Accepted
time: 3ms
memory: 48632kb

input:

6 7
1 2
1 3
1 6
2 4
3 4
3 5
4 6

output:

1011011

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #5:

score: 0
Accepted
time: 0ms
memory: 48644kb

input:

10 39
1 2
1 3
1 5
1 6
1 7
1 8
1 9
1 10
2 3
2 4
2 5
2 6
2 9
2 10
3 5
3 6
3 7
3 8
3 10
4 5
4 6
4 7
4 9
4 10
5 6
5 7
5 8
5 9
5 10
6 7
6 8
6 9
6 10
7 8
7 9
7 10
8 9
8 10
9 10

output:

111111111111111111111111111111111111111

result:

ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.

Test #6:

score: -100
Wrong Answer
time: 3ms
memory: 48780kb

input:

10 12
1 6
1 7
2 5
2 8
3 4
3 6
4 6
4 10
5 9
5 10
6 9
7 10

output:

110111110011

result:

wrong answer Deleting vertices 4 and 6 makes graph disconnected, but participant claims otherwise.