結果
問題 | No.2435 Order All Company |
ユーザー | 👑 potato167 |
提出日時 | 2023-08-15 22:56:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 1,892 bytes |
コンパイル時間 | 2,669 ms |
コンパイル使用メモリ | 212,676 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-03 09:21:09 |
合計ジャッジ時間 | 4,435 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 71 ms
5,376 KB |
testcase_06 | AC | 71 ms
5,376 KB |
testcase_07 | AC | 46 ms
5,376 KB |
testcase_08 | AC | 68 ms
5,376 KB |
testcase_09 | AC | 70 ms
5,376 KB |
testcase_10 | AC | 5 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 7 ms
5,376 KB |
testcase_14 | AC | 42 ms
5,376 KB |
testcase_15 | AC | 47 ms
5,376 KB |
testcase_16 | AC | 34 ms
5,376 KB |
testcase_17 | AC | 69 ms
5,376 KB |
testcase_18 | AC | 32 ms
5,376 KB |
testcase_19 | AC | 31 ms
5,376 KB |
testcase_20 | AC | 31 ms
5,376 KB |
testcase_21 | AC | 36 ms
5,376 KB |
testcase_22 | AC | 41 ms
5,376 KB |
testcase_23 | AC | 24 ms
5,376 KB |
testcase_24 | AC | 40 ms
5,376 KB |
testcase_25 | AC | 40 ms
5,376 KB |
testcase_26 | AC | 37 ms
5,376 KB |
testcase_27 | AC | 40 ms
5,376 KB |
testcase_28 | AC | 32 ms
5,376 KB |
testcase_29 | AC | 39 ms
5,376 KB |
testcase_30 | AC | 42 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 4 ms
5,376 KB |
testcase_35 | AC | 9 ms
5,376 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(p) p.begin(),p.end() #define rep(i,a,b) for(int i=(int)a;i<(int)b;i++) const int mod=998244353; namespace po167{ long long rev(long long a,long long mod){ a%=mod; long long ans=1; long long H=mod-2; while(H){ if(H&1) ans=(ans*a)%mod; a=(a*a)%mod; H>>=1; } return ans; } long long Determinant_Matrix(std::vector<std::vector<long long>> G,long long MOD){ int N=G.size(); long long ans=1; for(int i=0;i<N;i++){ for(int j=i;j<N;j++){ G[j][i]=(G[j][i]%MOD+MOD)%MOD; if(G[j][i]!=0){ if(j!=i){ for(int k=i;k<N;k++){ std::swap(G[i][k],G[j][k]); } ans*=-1; } break; } } if(G[i][i]==0){ return 0; } ans=(ans*G[i][i])%MOD; long long R=rev(G[i][i],MOD); for(int j=i+1;j<N;j++){ long long D=(R*G[j][i])%MOD; for(int k=i;k<N;k++){ G[j][k]=(G[j][k]-(D*G[i][k])%MOD+MOD)%MOD; } } } return (ans+MOD)%MOD; } //行列木定理 long long Kirchhoffs_theorem(std::vector<std::vector<long long>> G,int MOD){ int N=G.size(); std::vector<std::vector<long long>> H(N-1,std::vector<long long>(N-1)); for(int i=0;i<N-1;i++){ for(int j=0;j<N;j++){ if(i==j) continue; H[i][i]=(H[i][i]+G[i][j])%MOD; if(j!=N-1){ H[i][j]=(MOD-G[i][j])%MOD; } } } return Determinant_Matrix(H,MOD); } } using po167::Determinant_Matrix; using po167::Kirchhoffs_theorem; int main(){ int N,K; cin>>N>>K; vector<vector<pair<int,int>>> p(K); rep(i,0,K){ int T; cin>>T; p[i].resize(T); rep(j,0,T){ int a,b; cin>>a>>b; a--,b--; p[i][j]={a,b}; } } ll ans=0; rep(i,0,1<<K){ ll S=1; vector G(N,vector<ll>(N)); rep(j,0,K){ if(i&(1<<j)){ for(auto x:p[j]) G[x.first][x.second]++,G[x.second][x.first]++; } else S*=-1; } ll tmp=Kirchhoffs_theorem(G,mod); ans=ans+S*tmp; } cout<<(ans%mod+mod)%mod<<"\n"; }