QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#590717 | #7854. 这不是一道数据结构题 | byron10000 | 15 | 99ms | 40524kb | C++17 | 3.2kb | 2024-09-26 10:28:51 | 2024-09-26 10:28:51 |
Judging History
answer
#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_) for(int V_=(A_), V_##_END=(B_); V_>=V_##_END; V_--)
#ifdef _WIN32
#define long __int64
#endif
using namespace std;
const int MAXN=2e5+10,MOD=1e9+7;
int n,m,nnd,deg[MAXN],nsquare; vector<int> G[MAXN];
int dfn[MAXN],low[MAXN],dfnc,stk[MAXN],stkp,bel[MAXN];
vector<int> vec[MAXN];
void tarjan(int u){
dfn[u]=low[u]=++dfnc; stk[++stkp]=u;
for(int v:G[u]){
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
if(low[v]==dfn[u]){
int c=0;
deg[u]++,c++;
++nnd; vec[nnd].push_back(u);
for(int w=0; w!=v; ) w=stk[stkp--],deg[w]++,c++,bel[w]=nnd,vec[nnd].push_back(w);
nsquare+=c>2;
}
}else low[u]=min(low[u],dfn[v]);
}
}
bool belcmp(int u,int v){ return bel[u]==bel[v]?u<v:bel[u]<bel[v]; }
set<pair<int,int>> G1[MAXN];
bool check(vector<int> U){
sort(U.begin()+1,U.end());
int rt=U[0];
for(int u:U){
if(u!=rt&&binary_search(G[u].begin(),G[u].end(),rt,belcmp)) G1[u].insert({rt,0}),G1[rt].insert({u,0});
auto it=lower_bound(G[u].begin(),G[u].end(),U[1],belcmp); auto jt=upper_bound(G[u].begin(),G[u].end(),U.back(),belcmp);
while(it!=jt) G1[u].insert({*(it++),0});
}
queue<int> q;
for(int u:U){
if(G1[u].size()==2) q.push(u);
}
int c=int(U.size());
while(q.size()){
int u=q.front(); q.pop();
if(G1[u].empty()) continue;
// cerr<<u<<"\n";
assert(G1[u].size()==2);
c--;
int v1=G1[u].begin()->first,v2=next(G1[u].begin())->first;
bool flag=false;
assert(G1[v1].lower_bound({u,0})->first==u); assert(G1[v2].lower_bound({u,0})->first==u);
G1[v1].erase(G1[v1].lower_bound({u,0})),G1[v2].erase(G1[v2].lower_bound({u,0}));
auto it=G1[v1].lower_bound({v2,0});
if(it!=G1[v1].end()&&it->first==v2) flag|=it->second,G1[v1].erase(it);
G1[v1].insert({v2,1});
it=G1[v2].lower_bound({v1,0});
if(it!=G1[v2].end()&&it->first==v1) flag|=it->second,G1[v2].erase(it);
G1[v2].insert({v1,1});
if(G1[v1].size()==2) q.push(v1);
if(G1[v2].size()==2) q.push(v2);
G1[u].clear();
if(flag) break;
}
for(int u:U) G1[u].clear();
return c==2;
}
long fac[MAXN],ans=1;
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
#else
// freopen("rated.in","r",stdin);
// freopen("rated.out","w",stdout);
#endif
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>m;
RNG(_,1,m,u,v) cin>>u>>v,G[u].push_back(v),G[v].push_back(u);
tarjan(1);
RNG(i,1,n) sort(G[i].begin(),G[i].end(),belcmp);
RNG(i,1,nnd){
if(vec[i].size()>2&&!check(move(vec[i]))){ cout<<0<<"\n"; return 0; }
}
ans=n;
fac[0]=1; RNG(i,1,n) fac[i]=fac[i-1]*i%MOD;
RNG(i,1,n) ans=ans*fac[deg[i]]%MOD;
// cerr<<ans<<"\n";
RNG(_,1,nsquare) ans=ans*2%MOD;
cout<<ans<<"\n";
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 3ms
memory: 24760kb
input:
7 9 1 2 2 3 3 4 1 5 2 5 2 6 5 6 5 7 6 7
output:
56
result:
ok single line: '56'
Test #2:
score: 5
Accepted
time: 2ms
memory: 24720kb
input:
10 14 10 9 4 1 7 10 3 5 9 6 1 7 8 5 2 7 8 6 4 10 9 3 8 7 4 5 7 3
output:
0
result:
ok single line: '0'
Test #3:
score: 5
Accepted
time: 3ms
memory: 26108kb
input:
10 14 7 9 5 1 2 1 8 3 6 5 4 2 10 6 8 1 7 10 7 1 2 8 3 4 6 3 9 1
output:
0
result:
ok single line: '0'
Test #4:
score: 5
Accepted
time: 6ms
memory: 23484kb
input:
10 15 4 9 6 8 6 1 3 2 3 10 2 7 3 6 1 9 9 5 1 8 3 8 10 6 5 8 3 7 7 10
output:
40
result:
ok single line: '40'
Subtask #2:
score: 5
Accepted
Test #5:
score: 5
Accepted
time: 78ms
memory: 40432kb
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: 5
Accepted
time: 99ms
memory: 39956kb
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: 5
Accepted
time: 76ms
memory: 40484kb
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: 5
Accepted
time: 91ms
memory: 39912kb
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: 5
Accepted
Dependency #2:
100%
Accepted
Test #9:
score: 5
Accepted
time: 81ms
memory: 39612kb
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:
845696751
result:
ok single line: '845696751'
Test #10:
score: 5
Accepted
time: 75ms
memory: 39652kb
input:
200000 200000 101889 44867 88241 190435 89839 146284 5148 128828 32602 156348 31195 126576 146414 147950 70778 100220 13083 26015 6144 91822 141590 111136 44593 74957 138472 185562 75610 171998 48845 71030 175023 164685 128735 168341 15747 73835 169514 55205 119817 136636 190706 86265 148598 41994 1...
output:
654417965
result:
ok single line: '654417965'
Test #11:
score: 5
Accepted
time: 71ms
memory: 39936kb
input:
200000 200000 153577 8632 61036 84864 7655 90000 148729 89342 137385 7553 10222 50803 46720 102913 47837 105292 110223 81670 91157 108026 153903 139607 13230 84612 18282 113252 45158 195698 100923 170852 105927 41217 65631 826 105522 53451 173143 188641 176689 86349 150960 193904 15934 34208 72591 1...
output:
30336343
result:
ok single line: '30336343'
Test #12:
score: 5
Accepted
time: 74ms
memory: 40524kb
input:
200000 200000 139569 146207 179144 129709 26078 199032 175722 54209 174513 62650 157339 171357 119600 146013 50746 126175 183634 29260 30876 146213 53398 117000 115599 60981 90560 139790 2685 32865 53251 13733 60624 85594 41186 142244 157755 21032 167206 188574 161858 198651 157000 150869 113701 751...
output:
184856401
result:
ok single line: '184856401'
Subtask #4:
score: 0
Runtime Error
Test #13:
score: 0
Runtime Error
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:
result:
Subtask #5:
score: 0
Runtime Error
Test #18:
score: 0
Runtime Error
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:
result:
Subtask #6:
score: 0
Runtime Error
Test #23:
score: 20
Accepted
time: 5ms
memory: 24180kb
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:
600
result:
ok single line: '600'
Test #24:
score: 20
Accepted
time: 0ms
memory: 26640kb
input:
300 597 145 168 81 149 192 248 114 243 113 25 201 259 190 156 225 40 127 199 225 33 229 4 298 36 243 81 31 163 192 294 258 31 8 299 210 28 87 143 180 205 270 281 257 174 173 187 203 128 179 292 34 4 292 236 288 248 78 255 7 239 191 124 227 194 113 187 270 93 164 238 256 37 121 88 279 133 11 99 189 1...
output:
600
result:
ok single line: '600'
Test #25:
score: 20
Accepted
time: 0ms
memory: 24068kb
input:
300 597 137 70 124 146 24 239 38 218 186 180 244 153 274 153 274 298 256 126 36 174 172 157 60 274 270 87 207 14 114 280 221 51 165 106 166 25 29 62 210 122 104 157 218 173 134 154 65 120 131 46 45 262 138 253 48 187 118 114 101 184 47 244 200 60 296 267 34 128 129 165 53 246 102 123 153 238 238 249...
output:
600
result:
ok single line: '600'
Test #26:
score: 20
Accepted
time: 3ms
memory: 26504kb
input:
300 597 279 221 253 68 255 267 293 234 88 82 272 133 157 107 129 78 221 160 45 205 8 197 295 127 212 288 232 224 274 23 101 65 4 272 112 300 51 225 221 236 213 236 166 182 87 57 236 254 295 259 28 128 124 39 157 177 133 49 64 45 291 94 161 111 98 144 244 92 135 64 39 44 171 244 241 238 268 296 208 2...
output:
0
result:
ok single line: '0'
Test #27:
score: 20
Accepted
time: 6ms
memory: 23536kb
input:
300 597 240 186 292 198 221 201 168 95 237 175 71 272 55 257 181 281 47 115 188 83 251 142 297 77 271 181 68 75 267 209 195 92 22 54 134 300 253 251 238 13 179 199 246 144 61 199 65 271 113 46 180 204 144 209 84 184 124 250 238 212 70 30 118 125 175 39 88 54 253 159 208 243 115 262 30 128 214 22 187...
output:
0
result:
ok single line: '0'
Test #28:
score: 0
Runtime Error
input:
300 597 166 131 24 224 206 54 208 109 243 157 191 268 162 109 260 285 238 144 193 283 57 12 145 76 186 192 24 72 96 243 80 137 144 127 59 87 50 106 179 170 93 261 249 66 160 210 177 239 183 287 226 249 115 195 252 153 289 284 93 144 280 227 289 170 17 210 14 217 154 54 149 177 138 88 294 230 211 93 ...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #7:
0%