QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373508#7854. 这不是一道数据结构题NATURAL60 66ms48668kbC++172.1kb2024-04-01 19:30:112024-04-01 19:30:11

Judging History

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

  • [2024-04-01 19:30:11]
  • 评测
  • 测评结果:0
  • 用时:66ms
  • 内存:48668kb
  • [2024-04-01 19:30:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
inline long long qread()
{
	long long a=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
	return a*f;
}
int n,m,ans,dfn[200010],low[200010],tot,que[200010],ed,cnt,jc[200010];
int deg[200010],fa[200010],vis[200010];
vector<int>e[200010],S;
vector< pair<int,int> >eg[200010];
map<int,int>E[400010];
queue<int>qu;
inline void tarjan(int rt)
{
	dfn[rt]=low[rt]=++tot;que[++ed]=rt;
	for(int i:e[rt])
	{
		if(!dfn[i])
		{
			tarjan(i);
			low[rt]=min(low[rt],low[i]);
			if(low[i]>=dfn[rt])
			{
				++cnt;
				++deg[rt],++deg[cnt];fa[cnt]=rt;
				do{
					++deg[que[ed]];
					++deg[cnt];
					fa[que[ed]]=cnt;
				}while(que[ed--]^i);
			}
		}
		else low[rt]=min(low[rt],dfn[i]);
	}
	return ;
}
int main()
{
	cnt=n=qread(),m=qread();jc[0]=1;
	for(int i=1;i<=n;++i)jc[i]=1ll*jc[i-1]*i%mod;
	for(int i=1,u,v;i<=m;++i)
	{
		u=qread(),v=qread();
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	tarjan(1);
	for(int i=1;i<=n;++i)for(int j:e[i])if(i<j)
	{
		if(fa[fa[i]]==j)eg[fa[i]-n].emplace_back(make_pair(i,j));
		else eg[fa[j]-n].emplace_back(make_pair(i,j));
	}
	for(int i=1;i<=cnt-n;++i)
	{
		S.clear();
		for(pair<int,int>j:eg[i])
		{
			if(!vis[j.first])S.emplace_back(j.first),vis[j.first]=1;
			if(!vis[j.second])S.emplace_back(j.second),vis[j.second]=1;
			E[j.first][j.second]=E[j.second][j.first]=0;
		}
		for(int j:S)if(E[j].size()==2)qu.push(j);
		while(!qu.empty())
		{
			int p=qu.front();qu.pop();
			if(E[p].size()^2)continue;
			int A=E[p].begin()->first,B=prev(E[p].begin())->first;
			E[A].erase(p);E[B].erase(p);E[p].clear();
			if(E[A][B])continue;
			E[A][B]=E[B][A]=1;
			if(E[A].size()==2)qu.push(A);
			if(E[B].size()==2)qu.push(B);
		}
		tot=0;
		for(int j:S)tot+=(E[j].size()>0),E[j].clear(),vis[j]=0;
		if(tot^2)
		{
			puts("0");
			return 0;
		}
	}
	ans=n;
	for(int i=1;i<=n;++i)ans=1ll*ans*jc[deg[i]]%mod;
	for(int i=n+1;i<=cnt;++i)if(deg[i]^2)ans=1ll*ans*2%mod;
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 36692kb

input:

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

output:

0

result:

wrong answer 1st lines differ - expected: '56', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 66ms
memory: 48668kb

input:

200000 199999
76849 117660
190775 11517
36929 136177
161792 186900
165326 184615
74197 120051
7891 83240
121896 35204
83314 195652
104144 158348
71191 182187
122824 50031
108950 179173
165120 190230
156949 181392
171984 82834
96017 30143
58114 108979
38698 90371
185399 171751
139913 99465
71566 1324...

output:

0

result:

wrong answer 1st lines differ - expected: '437454115', found: '0'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 0ms
memory: 36628kb

input:

300 305
289 290
34 35
111 140
90 93
233 240
110 271
116 117
12 21
141 142
53 57
21 85
99 102
34 42
183 184
240 264
252 253
223 224
159 160
126 131
112 113
28 33
50 52
204 208
185 188
46 50
262 264
197 199
111 136
259 261
290 294
49 50
263 264
210 212
291 294
203 208
184 185
120 121
111 131
210 240
2...

output:

0

result:

wrong answer 1st lines differ - expected: '482487615', found: '0'

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 8ms
memory: 36056kb

input:

300 500
279 256
263 65
40 62
236 256
8 193
164 235
242 256
27 219
72 244
49 253
289 261
162 113
196 199
121 222
293 245
33 186
206 279
111 139
97 15
203 24
245 157
184 59
188 90
239 283
42 5
107 108
267 51
200 126
286 282
293 59
42 261
276 216
152 6
92 220
225 69
88 166
179 109
158 144
133 18
147 18...

output:

0

result:

wrong answer 1st lines differ - expected: '159215763', found: '0'

Subtask #6:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 0ms
memory: 36300kb

input:

300 597
181 11
16 186
144 42
80 274
72 186
238 172
7 268
225 118
198 84
274 214
170 27
181 44
171 74
270 266
20 6
296 108
45 25
32 198
99 86
129 110
281 273
67 47
259 107
277 265
264 145
215 218
264 164
156 281
100 23
284 125
109 280
92 203
108 74
227 171
213 81
262 239
206 111
5 23
90 121
77 274
23...

output:

0

result:

wrong answer 1st lines differ - expected: '600', found: '0'

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%