QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287144 | #7854. 这不是一道数据结构题 | chenxinyang2006 | 0 | 4ms | 42652kb | C++14 | 6.8kb | 2023-12-19 19:52:03 | 2023-12-19 19:52:03 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
template <int P>
class mod_int
{
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const
{
Z res = 1, t = *this;
while (k)
{
if (k & 1)
res *= t;
if (k >>= 1)
t *= t;
}
return res;
}
Z &operator++()
{
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--()
{
x ? --x : x = P - 1;
return *this;
}
Z operator++(int)
{
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int)
{
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs)
{
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs)
{
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z operator-()
{
return -x;
}
Z &operator*=(const Z &rhs)
{
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) \
{ \
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
friend istream& operator>>(istream& is, mod_int& x)
{
long long tmp;
is >> tmp;
x = tmp;
return is;
}
friend ostream& operator<<(ostream& os, const mod_int& x)
{
os << x.val();
return os;
}
};
using Z = mod_int<mod>;
Z power(Z p,ll k){
Z ans = 1;
while(k){
if(k % 2 == 1) ans *= p;
p *= p;
k /= 2;
}
return ans;
}
int n,m;
int _u[200005],_v[200005];
Z fact[200005];
int cnt;
int head[200005];
struct eg{
int to,nxt;
}edge[400005];
void make(int u,int v){
edge[++cnt].to = v;
edge[cnt].nxt = head[u];
head[u] = cnt;
}
int dfn[200005],low[200005],N;
vector <int> sta,scc[200005],idx[200005];
void tarjan(int u){
dfn[u] = low[u] = ++cnt;
sta.eb(u);
for(int i = head[u];i;i = edge[i].nxt){
int v = edge[i].to;
if(!dfn[v]){
tarjan(v);
chkmin(low[u],low[v]);
if(low[v] == dfn[u]){
++N;
scc[N].eb(u);
while(1){
int p = sta.back();
sta.pop_back();
scc[N].eb(p);
if(p == v) break;
}
}
}else{
chkmin(low[u],dfn[v]);
}
}
}
vector <int> son[400005];
int anc[400005];
void dfs(int u,int f){
anc[u] = f;
for(int v:son[u]) if(v != f) dfs(v,u);
}
queue <int> Q;
int deg[200005],qwq[200005];
map <int,int> G[200005];
void add(int u,int v){
qwq[u]++;qwq[v]++;
make(u,v);
make(v,u);
}
void test(int u){
deg[u]--;
if(deg[u] == 2) Q.push(u);
}
int vis[200005];
void dfs2(int u){
vis[u] = 1;
for(int i = head[u];i;i = edge[i].nxt){
int v = edge[i].to;
if(!vis[v]) dfs2(v);
}
}
int rk[200005];
int main(){
// freopen("graph1.in","r",stdin);
scanf("%d%d",&n,&m);
fact[0] = 1;
rep(i,1,n) fact[i] = fact[i - 1] * i;
rep(i,1,m){
scanf("%d%d",&_u[i],&_v[i]);
make(_u[i],_v[i]);make(_v[i],_u[i]);
}
cnt = 0;
tarjan(1);
rep(c,1,N){
for(int u:scc[c]){
son[n + c].eb(u);
son[u].eb(n + c);
}
}
dfs(1,0);
rep(i,1,m){
if(anc[_u[i]] == anc[_v[i]]){
idx[anc[_u[i]]].eb(i);
continue;
}
if(anc[anc[_u[i]]] == _v[i]) idx[anc[_u[i]]].eb(i);
else if(anc[anc[_v[i]]] == _u[i]) idx[anc[_v[i]]].eb(i);
else assert(0);
}
// printf("qwq\n");
Z ans = n;
cnt = 0;
memset(head,0,sizeof(head));
rep(c,1,N){
if(SZ(scc[c]) == 2){
add(_u[idx[n + c].back()],_v[idx[n + c].back()]);
qwq[_u[idx[n + c].back()]] = qwq[_v[idx[n + c].back()]] = 0;
continue;
}
/* printf("vcc %d\n",c);
for(int id:idx[n + c]) printf("%d ",id);
printf("\n");
for(int u:scc[c]) printf("%d ",u);
printf("\n");*/
ans *= 2;
for(int id:idx[n + c]){
G[_u[id]][_v[id]] = 1;
G[_v[id]][_u[id]] = 1;
deg[_u[id]]++;deg[_v[id]]++;
}
for(int u:scc[c]) if(deg[u] == 2) Q.push(u);
rep(k,1,SZ(scc[c]) - 2){
if(Q.empty()){
printf("0\n");
return 0;
}
int u = Q.front();
Q.pop();
int p = -1,q = -1;
for(pii I:G[u]){
if(!I.second) continue;
if(p == -1) p = I.first;
else if(q == -1) q = I.first;
else assert(0);
if(I.second == 1) add(u,I.first);
}
// printf("erase %d p=%d q=%d\n",u,p,q);
assert(q != -1);
G[p][u] = G[q][u] = 0;
G[u].clear();
if(G[p].find(q) != G[p].end() && G[p][q]){
test(p);
test(q);
}
G[p][q] = 2;
}
if(SZ(Q) < 2){
printf("0\n");
return 0;
}
assert(SZ(Q) == 2);
int p = Q.front();Q.pop();
int q = Q.front();Q.pop();
if(G[p][q] == 1) add(p,q);
G[p].clear();G[q].clear();
for(int u:scc[c]){
if(qwq[u] != 2){
printf("0\n");
return 0;
}
qwq[u] = 0;
}
}
dfs2(1);
rep(u,1,n){
if(!vis[u]){
printf("0\n");
return 0;
}
}
rep(c,1,N){
for(int u:scc[c]) rk[u]++;
}
rep(u,1,n) ans *= fact[rk[u]];
printf("%d\n",ans.val());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 5
Accepted
time: 4ms
memory: 40988kb
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: 0
Accepted
time: 4ms
memory: 42652kb
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
Runtime Error
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:
result:
Subtask #2:
score: 0
Runtime Error
Test #5:
score: 0
Runtime Error
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:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 3ms
memory: 41268kb
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: 0ms
memory: 40876kb
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: 3ms
memory: 40672kb
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%