結果

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

ソースコード

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
struct unionfind{
vector<int> par, sz;
unionfind() {}
unionfind(int n):par(n), sz(n, 1){
for(int i=0; i<n; i++) par[i]=i;
}
int find(int x){
if(par[x]==x) return x;
return par[x]=find(par[x]);
}
void unite(int x, int y){
x=find(x); y=find(y);
if(x==y) return;
if(sz[x]>sz[y]) swap(x, y);
par[x]=y;
sz[y]+=sz[x];
}
bool same(int x, int y){
return find(x)==find(y);
}
int size(int x){
return sz[find(x)];
}
};
int main()
{
int n, m, q; cin>>n>>m>>q;
string s[100010];
for(int i=0; i<n; i++){
cin>>s[i];
}
unionfind uf(7*n);
for(int i=0; i<n; i++){
for(int j=0; j<7; j++){
if(s[i][j]=='1' && s[i][(j+1)%7]=='1') uf.unite(7*i+j, 7*i+(j+1)%7);
}
}
vector<int> g[100010];
for(int i=0; i<m; i++){
int u, v; cin>>u>>v;
u--; v--;
g[u].push_back(v);
g[v].push_back(u);
for(int j=0; j<7; j++){
if(s[u][j]=='1' && s[v][j]=='1') uf.unite(7*u+j, 7*v+j);
}
}
for(int i=0; i<q; i++){
int t, x, y; cin>>t>>x>>y;
x--; y--;
if(t==1){
s[x][y]='1';
if(s[x][(y+1)%7]=='1') uf.unite(7*x+y, 7*x+(y+1)%7);
if(s[x][(y+6)%7]=='1') uf.unite(7*x+y, 7*x+(y+6)%7);
for(auto z:g[x]){
if(s[z][y]=='1') uf.unite(7*x+y, 7*z+y);
}
}else{
cout<<uf.size(7*x)<<endl;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0