結果

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

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << (x) << endl;
class UnionFind{
private:
vec<int> p,s;
int cnt;
public:
UnionFind(){}
UnionFind(int N):cnt(N),s(N,1),p(N){
iota(p.begin(),p.end(),0);
}
int find(int x){
if(p[x]==x) return x;
else return p[x] = find(p[x]);
}
void unite(int x,int y){
x = find(x); y = find(y);
if(x==y) return;
if(s[x]>s[y]) swap(x,y);
p[x] = y;
s[y] += s[x];
cnt--;
}
bool is_same_set(int x,int y) {return find(x)==find(y);}
int size(int x) {return s[find(x)];}
int compnents_number(){return cnt;}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,M,Q;
cin >> N >> M >> Q;
UnionFind uf(7*N);
auto node = [&](int v,int c){
return c*N+v;
};
vec<string> S(N);
auto update_color = [&](int i){
for(int j=0;j<7;j++){
for(int k=1;k<=1;k+=2){
int c = (j+k+7)%7;
if(S[i][j]=='1' && S[i][c]=='1') uf.unite(node(i,j),node(i,c));
}
}
};
for(int i=0;i<N;i++){
cin >> S[i];
update_color(i);
}
vvec<int> g(N);
for(int i=0;i<M;i++){
int a,b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
for(int j=0;j<7;j++) if(S[a][j]=='1' && S[b][j]=='1') uf.unite(node(a,j),node(b,j));
}
auto update = [&](int v,int c){
S[v][c] = '1';
update_color(v);
for(auto& u:g[v]) if(S[v][c]=='1' && S[u][c]=='1') uf.unite(node(v,c),node(u,c));
};
while(Q--){
int t,x,y;
cin >> t >> x >> y;
x--,y--;
if(t==1) update(x,y);
else cout << uf.size(node(x,0)) << "\n";
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0