結果

問題 No.1266 7 Colors
ユーザー kyoprouno
提出日時 2020-10-24 00:05:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 371 ms / 3,000 ms
コード長 3,762 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 190,172 KB
実行使用メモリ 29,008 KB
最終ジャッジ日時 2024-07-21 14:04:20
合計ジャッジ時間 9,514 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
using namespace std;
const ll INF=1e9+10;
class DisjointSet{
public:
vector<ll> rank,p,sz;
DisjointSet(){}
DisjointSet(ll size){ //
rank.resize(size,0);
p.resize(size,0);
sz.resize(size,1);
rep(i,size) makeSet(i);
}
void makeSet(ll x){ //x
p[x]=x;
rank[x]=0;
}
bool same(ll x,ll y){ //xy
return findSet(x)==findSet(y);
}
void unite(ll x, ll y){
link(findSet(x),findSet(y));
}
void link(ll x, ll y){ //rank
if(rank[x]>rank[y]){
p[y]=x;
}
else{
p[x]=y;
if(rank[x]==rank[y]){
rank[y]++; //xyrankrank1
}
}
sz[x]+=sz[y];
sz[y]=sz[x];
}
ll findSet(ll x){ //x
if(x!=p[x]){
p[x]=findSet(p[x]);
}
return p[x];
}
};
DisjointSet ds=DisjointSet(700005);
vector<vector<ll>> to;
/*void dfs(ll v,ll p=-1){
for(auto x:to[v]){
if(x==p) continue;
if(ds.same(x,v)) continue;
}
return ;
}*/
int main(){
ll n,m,q;
cin >> n >> m >> q;
vector<string> s(n);
to=vector<vector<ll>>(n);
rep(i,n){
cin >> s[i];
}
rep(i,m){
ll u,v;
cin >> u >> v;
u--, v--;
to[u].push_back(v);
to[v].push_back(u);
rep(j,7){
if(s[u][j]=='1' && s[v][j]=='1'){
ll from=7*u+j;
ll go=7*v+j;
if(!ds.same(from,go)){
ds.unite(from,go);
}
}
}
}
rep(i,n){
rep(j,7){
if(s[i][j]=='1' && s[i][(j+1)%7]=='1'){
ll from=7*i+j;
ll go=7*i+((j+1)%7);
if(!ds.same(from,go)){
ds.unite(from,go);
}
}
}
}
rep(i,q){
ll t;
cin >> t;
if(t==1){
ll x,y;
cin >> x >> y;
x--;
y--;
s[x][y]='1';
ll pre=(y-1+7)%7;
ll nxt=(y+1)%7;
if(s[x][pre]=='1'){
ll from=7*x+pre;
ll go=7*x+y;
if(!ds.same(from,go)){
ds.unite(from,go);
}
}
if(s[x][nxt]=='1'){
ll from=7*x+nxt;
ll go=7*x+y;
if(!ds.same(from,go)){
ds.unite(from,go);
}
}
for(auto w:to[x]){
if(s[w][y]=='1'){
ll from=7*w+y;
ll go=7*x+y;
if(!ds.same(from,go)){
ds.unite(from,go);
}
}
}
}
if(t==2){
ll x,buf;
cin >> x >> buf;
x--;
ll node=7*x;
cout << ds.sz[ds.findSet(node)] << endl;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0