QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267826#7854. 这不是一道数据结构题yyyyxh5 99ms147848kbC++232.6kb2023-11-27 19:09:192023-11-27 19:09:19

Judging History

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

  • [2023-11-27 19:09:19]
  • 评测
  • 测评结果:5
  • 用时:99ms
  • 内存:147848kb
  • [2023-11-27 19:09:19]
  • 提交

answer

#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=(x<<1)+(x<<3)+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=400003,M=800003,P=1000000007;
typedef long long ll;
int n,m,cnt;
int dfn[N],low[N],num;
int stk[N],tp,d[N],deg[N];
int hd[N],ver[M],nxt[M],tot;
int eu[M],ev[M],fac[M];
inline void add(int u,int v){nxt[++tot]=hd[u];hd[u]=tot;ver[tot]=v;}
inline void chmn(int &x,int v){if(x>v) x=v;}
ll res;
__gnu_pbds::gp_hash_table<int,bool> mp[N];
vector<int> e[N],vec[N];
namespace tr{
	int hd[N],ver[N<<1],nxt[N<<1],tot;
	inline void add(int u,int v){
		vec[u-n].emplace_back(v);++deg[v];
		nxt[++tot]=hd[u];hd[u]=tot;ver[tot]=v;
		nxt[++tot]=hd[v];hd[v]=tot;ver[tot]=u;
	}
	int ft[N],de[N];
	void dfs(int u,int fa){
		ft[u]=fa;de[u]=de[fa]+1;
		for(int i=hd[u];i;i=nxt[i])
			if(ver[i]!=fa) dfs(ver[i],u);
	}
	inline int finds(int x,int y){
		if(ft[x]==ft[y]) return ft[x]-n;
		if(de[x]<de[y]) return ft[y]-n;
		else return ft[x]-n;
	}
}
void tarjan(int u){
	low[u]=dfn[u]=++num;stk[++tp]=u;
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(dfn[v]) chmn(low[u],dfn[v]);
		else{
			tarjan(v);
			chmn(low[u],low[v]);
			if(low[v]==dfn[u]){
				int x;tr::add(++cnt,u);
				do tr::add(cnt,x=stk[tp--]);while(x!=v);
			}
		}
	}
}
bool solve(vector<int> V,vector<int> E){
	for(int x:E) ++d[eu[x]],++d[ev[x]],mp[eu[x]][ev[x]]=mp[ev[x]][eu[x]]=1;
	queue<int> que;
	for(int x:V) if(d[x]==2) que.emplace(x);
	for(int i=1;i<=int(V.size()-2);++i){
		if(que.empty()) return 1;
		int u=que.front();
		que.pop();
		int x=0,y=0;
		for(auto [p,c]:mp[u])
			if(c){
				if(x) y=p;
				else x=p;
			}
		mp[x][u]=mp[y][u]=0;
		if(mp[x][y]){
			if(--d[x]==2) que.emplace(x);
			if(--d[y]==2) que.emplace(y);
		}
		else mp[x][y]=mp[y][x]=1;
	}
	for(int x:V) d[x]=0,mp[x].clear();
	return 0;
}
int main(){
	n=read();m=read();cnt=n;fac[0]=1;
	for(int i=1;i<=m;++i){
		fac[i]=(ll)fac[i-1]*i%P;
		eu[i]=read();
		ev[i]=read();
		add(eu[i],ev[i]);add(ev[i],eu[i]);
	}
	tarjan(1);tr::dfs(1,0);
	for(int i=1;i<=m;++i) e[tr::finds(eu[i],ev[i])].emplace_back(i);
	int res=n;
	for(int i=1;i<=n;++i) res=(ll)res*fac[deg[i]]%P;
	for(int i=1;i<=cnt-n;++i){
		if(vec[i].size()<=2lu) continue;
		for(int x:vec[i]) printf("%d ",x);
		putchar('\n');
		if(solve(vec[i],e[i])){puts("0");return 0;}
		res<<=1;if(res>=P) res-=P;
	}
	printf("%d\n",res);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 27ms
memory: 118432kb

input:

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

output:

1 2 6 7 5 
56

result:

wrong answer 1st lines differ - expected: '56', found: '1 2 6 7 5 '

Subtask #2:

score: 5
Accepted

Test #5:

score: 5
Accepted
time: 73ms
memory: 147848kb

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:

437454115

result:

ok single line: '437454115'

Test #6:

score: 0
Accepted
time: 79ms
memory: 146796kb

input:

200000 199999
6574 23146
34257 69209
155380 164090
110026 127221
193115 99889
5635 174278
55712 77121
26697 49953
22754 96882
63538 126940
194879 165261
41026 41295
30210 92107
74413 48768
21400 93816
132836 161798
106855 181482
139713 172322
188984 22749
138035 187484
119125 94408
106547 197156
855...

output:

113291706

result:

ok single line: '113291706'

Test #7:

score: 0
Accepted
time: 99ms
memory: 147832kb

input:

200000 199999
31632 184606
168095 2953
125939 52574
192991 195231
89249 63587
67762 15189
127486 26911
55580 120635
164243 67832
132583 173571
144167 123204
145229 101807
103885 170616
134195 61189
192909 104601
164109 127893
96486 109669
155596 168629
144450 40523
111830 166912
21452 144116
168225 ...

output:

695768886

result:

ok single line: '695768886'

Test #8:

score: 0
Accepted
time: 87ms
memory: 144536kb

input:

200000 199999
163361 68930
19490 33356
160159 49369
191573 191277
25950 191040
87000 96084
87600 7514
36433 91932
124379 117605
192879 188658
132884 148743
167108 124881
145773 56391
131418 128073
157008 76084
141192 147983
85318 133420
94748 189411
50453 78717
71148 12192
164264 189793
112210 18103...

output:

733222740

result:

ok single line: '733222740'

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #9:

score: 0
Wrong Answer
time: 80ms
memory: 144824kb

input:

200000 200000
12724 99480
110070 33803
133108 189774
90549 132698
44107 190886
80834 45073
196688 3535
65325 152337
190962 142430
1881 60227
26322 185955
145062 99829
183113 179795
10631 100971
60798 37230
149752 51457
119906 123989
118777 44821
140764 181969
101534 197139
108651 135722
56961 189607...

output:

143996 87585 183841 182508 11078 46201 166861 44573 6914 49201 156227 40322 196705 25569 109459 77989 120446 91517 84509 50371 169590 193262 96295 2181 66977 149493 141212 12068 71745 148545 111309 171770 51754 118523 18105 111266 143357 182134 13916 179410 25646 199612 5830 189902 173044 171204 127...

result:

wrong answer 1st lines differ - expected: '845696751', found: '143996 87585 183841 182508 110...568 131053 149828 132444 91025 '

Subtask #4:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 24ms
memory: 118528kb

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:

21 42 50 
85 83 84 
102 99 98 96 93 
224 223 221 
203 208 204 
1 85 21 12 4 
482487615

result:

wrong answer 1st lines differ - expected: '482487615', found: '21 42 50 '

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 28ms
memory: 122504kb

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:

228 78 85 
197 120 251 175 
22 290 34 
200 73 11 207 
263 89 174 
91 86 46 
29 221 252 
37 84 91 81 230 29 47 
218 188 90 54 237 
42 26 210 7 38 
99 134 213 107 108 165 
156 264 75 
32 109 217 179 249 
257 211 71 10 273 149 145 185 60 
8 191 55 148 259 
59 184 266 140 299 116 48 125 
293 27 61 278 8...

result:

wrong answer 1st lines differ - expected: '159215763', found: '228 78 85 '

Subtask #6:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 33ms
memory: 124680kb

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:

1 239 115 271 207 50 146 52 279 280 81 109 182 269 161 213 57 155 63 66 56 237 98 70 160 31 138 235 59 29 99 24 15 170 83 3 196 27 150 124 296 289 184 165 123 295 194 97 198 37 34 210 282 230 236 228 140 231 113 168 62 195 251 61 119 248 111 222 281 64 82 253 7 87 212 299 71 159 267 41 273 156 249 2...

result:

wrong answer 1st lines differ - expected: '600', found: '1 239 115 271 207 50 146 52 27... 288 292 127 242 285 21 187 65 '

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%