結果

問題 No.1266 7 Colors
ユーザー chocono2230
提出日時 2020-10-23 23:23:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 404 ms / 3,000 ms
コード長 2,014 bytes
コンパイル時間 4,374 ms
コンパイル使用メモリ 255,480 KB
最終ジャッジ日時 2025-01-15 14:04:33
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
#include <atcoder/all>
using namespace atcoder;
void dfs(const vector<string> &s, const vector<vector<int>> &gr, int now, int color, dsu &d){
int bfc = (color - 1 + 7) % 7, nxc = (color + 1) % 7;
if(s.at(now).at(bfc) == '1' && d.same(now*7+color, now*7+bfc) == false){
d.merge(now*7+color, now*7+bfc);
dfs(s, gr, now, bfc, d);
}
if(s.at(now).at(nxc) == '1' && d.same(now*7+color, now*7+nxc) == false){
d.merge(now*7+color, now*7+nxc);
dfs(s, gr, now, nxc, d);
}
for(auto nx : gr.at(now)){
if(s.at(nx).at(color) == '1' && d.same(now*7+color, nx*7+color) == false){
d.merge(now*7+color, nx*7+color);
dfs(s, gr, nx, color, d);
}
}
}
int main(){
int n, m, q;
cin >> n >> m >> q;
vector<string> s(n);
rep(i, n) cin >> s.at(i);
vector<vector<int>> gr(n, vector<int>());
rep(i, m){
int a, b;
cin >> a >> b;
a--; b--;
gr.at(a).push_back(b);
gr.at(b).push_back(a);
}
dsu d(n*7);
rep(i, n){
rep(j, 7){
if(s.at(i).at(j) == '1'){
dfs(s, gr, i, j, d);
}
}
}
rep(iq, q){
int mode, x, y;
cin >> mode >> x >> y;
x--; y--;
if(mode == 1){
s.at(x).at(y) = '1';
int nxc = (y+1) % 7, bfc = (y-1+7) % 7;
if(s.at(x).at(nxc) == '1'){
d.merge(x*7+y, x*7+nxc);
}
if(s.at(x).at(bfc) == '1'){
d.merge(x*7+y, x*7+bfc);
}
for(auto nx : gr.at(x)){
if(s.at(nx).at(y) == '1'){
d.merge(x*7+y, nx*7+y);
}
}
}else{
cout << d.size(x*7) << endl;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0