結果
| 問題 |
No.1116 Cycles of Dense Graph
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2020-07-17 23:17:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,036 bytes |
| コンパイル時間 | 1,471 ms |
| コンパイル使用メモリ | 167,976 KB |
| 実行使用メモリ | 30,232 KB |
| 最終ジャッジ日時 | 2024-11-30 03:00:28 |
| 合計ジャッジ時間 | 17,669 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 3 WA * 32 TLE * 3 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void solve();
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
#if DEBUG
#define SIZE 5
#else
#define SIZE 15
#endif
int N,M;
pair<int, int> P[SIZE];
const int MAX = 5e5;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
if (!fac[n]) COMinit();
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//int P(int n, int k) {
// if (n < k) return 0;
// if (n < 0 || k < 0) return 0;
// if (!fac[n]) COMinit();
// return (fac[n] * finv[n-k]) % MOD;
//}
template<int MOD> struct ModInt {
static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
return ModInt(u); }
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<998244353> mint;
/*
完全グラフのサイクル数-1つ抜いたサイクル数+...
(包除原理)
選ぶ辺が1つの場合、それ以外を一つも選ばないパターンを除く必要あり
同じ頂点が3回出てきたらx
すべての頂点が複数回なら→1通り
結合後の辺の数...k通り
辺に含まれる頂点数...g個
辺に含まれない頂点をl個選ぶ場合...COM(N-g,l) * (k+l-1)! * 2^(k-1)
*/
void solve() {
cin>>N>>M;
REP(i,M) {
cin>>P[i].first>>P[i].second;
P[i].first--;
P[i].second--;
}
COMinit();
mint ans = 0;
REP(i,1LL<<M) {
map<int,int> C;
REP(j,M) if (i & 1LL<<j) {
C[P[j].first]++;
C[P[j].second]++;
}
int ok = true;
int all_even = true;
for (auto p:C) {
if (p.second >= 3) ok = false;
if (p.second%2) all_even = false;
}
if (!ok) continue;
if (C.size() && all_even) {
ans += 1;
continue;
}
bitset<20> bs(i);
int k = bs.count(); // 辺の数
int g = C.size(); // 頂点数
int start = 0;
if (g==0) start = 3;
if (g==2) start = 1;
FOR(l,start,N-g+1) {
mint add = 1;
add *= COM(N-g,l);
if (k+l>2) add *= fac[k+l-1] * inv[2];
if (k) add *= mint(2)^(k-1);
if (k%2==0) {
ans += add;
} else {
ans -= add;
}
}
}
cout << ans << endl;
}
koyopro