結果
| 問題 |
No.2274 三角彩色
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2023-04-14 22:51:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,440 bytes |
| コンパイル時間 | 4,081 ms |
| コンパイル使用メモリ | 259,852 KB |
| 最終ジャッジ日時 | 2025-02-12 07:34:50 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
void Gauss(vector<bitset<405>> &B){
int now = 0;
rep(i,405){
int temp = -1;
for(int j=now;j<B.size();j++){
if(B[j][i]){
temp = j;
break;
}
}
if(temp==-1)continue;
rep(j,B.size()){
if(temp==j)continue;
if(B[j][i])B[j] ^= B[temp];
}
swap(B[now],B[temp]);
now++;
}
while(B.size()>0 && B.back()==bitset<405>())B.pop_back();
}
int main(){
long long n,m,b,q;
cin>>n>>m>>b>>q;
vector<long long> u(m),v(m);
vector<long long> t;
rep(i,m){
cin>>u[i]>>v[i];
t.push_back(u[i]);
t.push_back(v[i]);
}
sort(t.begin(),t.end());
t.erase(unique(t.begin(),t.end()),t.end());
rep(i,m){
u[i] = distance(t.begin(),lower_bound(t.begin(),t.end(),u[i]));
v[i] = distance(t.begin(),lower_bound(t.begin(),t.end(),v[i]));
}
dsu D(t.size());
long long cnt = 0;
rep(i,m){
if(D.same(u[i],v[i]))cnt++;
else D.merge(u[i],v[i]);
}
vector<bitset<405>> Bs(q);
rep(i,q){
int x,y,z;cin>>x>>y>>z;
Bs[i][x] =1;
Bs[i][y] =1;
Bs[i][z] =1;
}
Gauss(Bs);
long long T = 1;
rep(i,Bs.size()){
T *= 2;
T %= b;
}
long long S = 1;
rep(i,cnt){
S *= 2;
S %= b;
}
S -= T;
if(S<0)S += b;
S %= b;
cout<<S<<' '<<T<<endl;
return 0;
}
沙耶花