結果
| 問題 |
No.1483 Many Graph in Namori
|
| コンテスト | |
| ユーザー |
PCTprobability
|
| 提出日時 | 2021-03-07 15:52:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,056 bytes |
| コンパイル時間 | 5,704 ms |
| コンパイル使用メモリ | 253,216 KB |
| 最終ジャッジ日時 | 2025-01-19 12:39:50 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 WA * 17 RE * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define P pair<ll,ll>
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
void vcin(vector<ll> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
void vcout(vector<ll> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
using mint = modint998244353;
class UnionFind{
public:
vector<ll> par;
vector<ll> siz;
UnionFind(ll sz_):par(sz_),siz(sz_,1ll){
for(int i=0;i<sz_;i++) par[i]=i;
}
void init(ll sz_){
par.resize(sz_);
siz.assign(sz_,1ll);
for(int i=0;i<sz_;i++) par[i]=i;
}
ll root(ll x){
while(par[x]!=x){
x=par[x]=par[par[x]];
}
return x;
}
bool merge(ll x,ll y){
x=root(x);
y=root(y);
if(x==y) return false;
if(siz[x]<siz[y]) swap(x,y);
siz[x]+=siz[y];
par[y]=x;
return true;
}
bool issame(ll x,ll y){
return root(x)==root(y);
}
ll size(ll x){
return siz[root(x)];
}
};
int main() {
/* mod は 1e9+7 */
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
ll a,b;
cin>>a>>b;
vector<ll> l(a),r(a);
for(int i=0;i<a;i++){
cin>>l[i]>>r[i];
l[i]--;
r[i]--;
}
mint ans=b*a*mint(1-b).pow(a-1);
// cout<<ans.val()<<endl;
for(int i=1;i<(1<<a);i++){
UnionFind t(a);
vector<ll> g(a);
bitset<20> s(i);
for(int j=0;j<a;j++){
if(s.test(j)){
g[l[j]]++;
g[r[j]]++;
t.merge(l[j],r[j]);
}
}
bool c=true;
for(int j=0;j<a;j++){
for(int k=0;k<a;k++){
if(g[j]&&g[k]){
if(!t.issame(j,k)){
c=false;
}
}
}
}
if(c){
ll x=0,y=0;
for(int j=0;j<a;j++){
if(g[j]>=2){
x++;
}
if(g[j]==1){
y++;
}
}
/*cout<<i<<" "<<x<<" "<<y<<" "<<(mint(b).pow(y)*mint(1-b).pow(a-x-y)*(x+y)).val()<<endl;
for(int j=0;j<a;j++){
cout<<g[j]<<" ";
}
cout<<endl;*/
ans+=mint(b).pow(y)*mint(1-b).pow(a-x-y)*(x+y);
}
}
cout<<ans.val()<<endl;
}
PCTprobability