結果

問題 No.2274 三角彩色
ユーザー 沙耶花沙耶花
提出日時 2023-04-14 22:51:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 4,861 ms
コンパイル使用メモリ 263,520 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 20:26:16
合計ジャッジ時間 5,990 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0