QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185919#5670. Group Guests275307894aWA 463ms410172kbC++143.0kb2023-09-22 20:01:162023-09-22 20:01:16

Judging History

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

  • [2023-09-22 20:01:16]
  • 评测
  • 测评结果:WA
  • 用时:463ms
  • 内存:410172kb
  • [2023-09-22 20:01:16]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=4e6+5,M=N*20+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
int m,n,X[N],Y[N],In[N];vector<int> S[N],G[N];
int dep[N];
int dp[N],flag;
vector<int> pot;
int sum;
void dfs1(int x,int La){
	pot.emplace_back(x);sum++;
	dp[x]=(La>0);dep[x]=dep[La]+1;
	for(int i:S[x]) if(!dep[i]){
		dfs1(i,x);dp[x]+=dp[i];sum--;
	}else if(dep[x]<dep[i]) dp[x]++,sum--;
	int Ct=dp[x];
	for(int i:S[x]) if(i^La&&dep[i]<dep[x]) Ct++;
	if(Ct>=3) flag=1;dp[x]&=1;
}
int dfn[N],low[N],dh,st[N],sh,Ct,fa[N],Si[N];vector<int> P[N];
void con(int x,int y){P[x].emplace_back(y);P[y].emplace_back(x);}
void dfs2(int x,int La){
	dfn[x]=low[x]=++dh;st[++sh]=x;
	for(int i:S[x]) if(i^La){
		if(dfn[i]) {low[x]=min(low[x],dfn[i]);continue;}dfs2(i,x);low[x]=min(low[x],low[i]);
		if(low[i]>=dfn[x]){con(++Ct,x);/*cerr<<"Pt "<<Ct<<'\n'<<x<<' ';*/while(st[sh+1]^i) /*cerr<<st[sh]<<' ',*/con(Ct,st[sh--]);/*cerr<<'\n';*/}
	}
}
void dfs3(int x,int La){fa[x]=La;for(int i:P[x]) if(i^La) dfs3(i,x);}
void dfs4(int x,int La){for(int i:P[x]) if(i^La) dfs4(i,x),Si[x]+=Si[i];}
int g[N],gs[N];
int check(int x,int y,int z){
	cerr<<x<<' '<<y<<' '<<z<<'\n';
	int cir=fa[x];if(fa[y]==fa[z]) cir=fa[y];
	cerr<<cir<<'\n';
	auto find=[&cir](int x){
		if(fa[x]==cir){
			if(g[x]==2&&Si[x]&1) return 0;
		} else{
			if(g[cir]==2&&!(Si[cir]&1)) return 0;
		}
		return 1;
	};
	cerr<<find(z)<<'\n';
	return find(x)&&find(y)&&find(z);
}
int calc(){
	for(int i:pot){
		for(int j:G[i]) gs[j]++;
		for(int j:G[i]) for(int h:G[j]) if(gs[h]&&check(i,j,h)) return 1;
		for(int j:G[i]) gs[j]=0;
	}
	return 0;
}
void Solve(){
	int i,j;scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++) scanf("%d%d",&X[i],&Y[i]),In[X[i]]++,In[Y[i]]++;
	for(i=1;i<=m;i++) S[X[i]].emplace_back(Y[i]),S[Y[i]].emplace_back(X[i]);
	for(i=1;i<=m;i++){
		if(In[X[i]]>In[Y[i]]) swap(X[i],Y[i]);
		G[X[i]].emplace_back(Y[i]);
	} 
	int ans1=0,ans2=0;Ct=n;
	for(i=1;i<=n;i++) if(!dep[i]){
		pot.clear();flag=sum=0;dfs1(i,0);if(!dp[i]) continue;
		int LC=Ct;sh=0;dfs2(i,0);dfs3(i,0);
		for(int j:pot) for(int h:S[j]) {
			if(fa[h]==fa[j]||fa[fa[j]]==h) g[j]++,dfn[j]<dfn[h]&&(Si[fa[j]]++);else g[fa[h]]++,dfn[j]<dfn[h]&&(Si[fa[h]]++);
		}
		dfs4(i,0);//if(i%1000==0) cerr<<pot.size()<<' '<<Ct<<' '<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
		if(calc()) continue;
		for(j=LC+1;j<=Ct;j++) if(Si[j]>P[j].size()) flag=1;
		if(!flag) ans1++;
		else ans2++;
	}
	printf("%d %d\n",ans1,ans2);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 31ms
memory: 302784kb

input:

2 4
1 2
3 4

output:

2 0

result:

ok single line: '2 0'

Test #2:

score: 0
Accepted
time: 36ms
memory: 294756kb

input:

2 3
1 2
3 1

output:

0 0

result:

ok single line: '0 0'

Test #3:

score: 0
Accepted
time: 50ms
memory: 300844kb

input:

5 5
1 2
2 3
2 4
5 2
5 4

output:

0 0

result:

ok single line: '0 0'

Test #4:

score: 0
Accepted
time: 456ms
memory: 401280kb

input:

999990 666660
1 2
1 5
1 7
1 8
1 9
1 10
2 4
2 6
2 9
2 10
3 4
4 8
5 8
6 7
6 10
11 13
11 15
11 20
12 17
12 19
13 16
13 19
14 16
14 19
15 17
15 18
16 17
16 19
17 18
17 20
21 26
21 27
21 29
22 26
22 27
22 29
23 26
23 30
24 26
24 28
25 27
25 30
26 27
26 29
28 29
31 33
31 40
32 35
33 35
33 37
33 38
33 39
3...

output:

383 523

result:

ok single line: '383 523'

Test #5:

score: 0
Accepted
time: 428ms
memory: 403776kb

input:

999990 666660
1 2
1 3
1 5
1 8
2 4
2 7
3 8
3 9
3 10
4 5
4 10
5 9
6 7
6 9
9 10
11 12
11 14
11 19
11 20
12 16
13 17
13 19
14 15
14 16
15 16
15 18
16 18
16 19
17 20
18 20
21 24
21 26
21 28
22 23
23 24
23 27
23 28
24 25
24 27
25 26
25 27
25 30
26 29
27 29
27 30
31 32
31 36
31 37
32 37
33 34
33 35
33 39
3...

output:

349 522

result:

ok single line: '349 522'

Test #6:

score: 0
Accepted
time: 44ms
memory: 298748kb

input:

4 4
1 2
2 4
2 3
3 4

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: 0
Accepted
time: 463ms
memory: 401144kb

input:

999991 647053
1 2
1 4
1 7
1 8
1 10
2 4
2 9
3 8
3 9
3 11
4 6
6 10
7 9
7 11
8 9
9 10
10 11
12 13
12 15
12 21
13 16
13 19
13 22
14 17
14 19
14 20
15 19
15 22
16 20
17 18
17 19
18 20
19 22
20 21
23 25
23 27
23 28
23 30
24 25
24 31
24 32
25 30
25 31
26 32
26 33
27 30
28 32
29 31
29 32
29 33
30 31
34 37
3...

output:

375 322

result:

ok single line: '375 322'

Test #8:

score: 0
Accepted
time: 455ms
memory: 404340kb

input:

999991 647053
1 8
2 7
2 9
2 11
3 6
4 5
5 7
5 8
5 9
5 10
5 11
6 8
6 10
8 9
8 10
8 11
10 11
12 13
12 16
12 22
13 14
13 15
13 16
15 18
15 20
15 22
16 19
16 20
16 21
17 18
17 20
19 22
20 22
21 22
23 24
23 26
23 28
23 33
24 25
24 30
25 26
25 29
25 33
26 32
26 33
28 29
28 31
28 33
29 33
31 33
32 33
34 36
...

output:

366 307

result:

ok single line: '366 307'

Test #9:

score: 0
Accepted
time: 39ms
memory: 302880kb

input:

5 5
1 2
2 4
2 3
5 4
3 4

output:

0 1

result:

ok single line: '0 1'

Test #10:

score: -100
Wrong Answer
time: 440ms
memory: 410172kb

input:

999991 705876
1 5
1 9
2 5
2 7
2 8
3 4
5 6
6 7
6 9
6 10
6 11
6 12
7 9
7 11
8 10
9 10
11 12
13 14
13 15
13 16
13 18
13 19
14 17
15 19
15 21
16 21
17 19
18 24
19 20
20 21
21 22
21 23
22 23
23 24
25 28
25 31
25 34
26 31
27 28
27 32
28 29
28 33
28 36
29 32
29 33
29 36
30 35
31 34
31 35
32 34
32 35
37 45
...

output:

1028 1380

result:

wrong answer 1st lines differ - expected: '1032 1376', found: '1028 1380'