結果

問題 No.1266 7 Colors
ユーザー umezoumezo
提出日時 2020-10-23 23:59:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 3,000 ms
コード長 1,765 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 210,812 KB
実行使用メモリ 28,576 KB
最終ジャッジ日時 2023-09-28 19:19:59
合計ジャッジ時間 9,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,728 KB
testcase_01 AC 4 ms
5,772 KB
testcase_02 AC 3 ms
5,720 KB
testcase_03 AC 248 ms
9,396 KB
testcase_04 AC 320 ms
21,280 KB
testcase_05 AC 255 ms
10,588 KB
testcase_06 AC 331 ms
23,072 KB
testcase_07 AC 340 ms
25,820 KB
testcase_08 AC 318 ms
21,988 KB
testcase_09 AC 299 ms
17,912 KB
testcase_10 AC 297 ms
16,200 KB
testcase_11 AC 261 ms
12,040 KB
testcase_12 AC 266 ms
13,480 KB
testcase_13 AC 284 ms
14,672 KB
testcase_14 AC 249 ms
10,460 KB
testcase_15 AC 337 ms
26,476 KB
testcase_16 AC 271 ms
13,624 KB
testcase_17 AC 332 ms
25,104 KB
testcase_18 AC 282 ms
28,576 KB
testcase_19 AC 169 ms
28,132 KB
testcase_20 AC 170 ms
27,940 KB
testcase_21 AC 223 ms
6,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

class Dis{
  public:
  vector<ll> rank,p,siz;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    siz.resize(s,1);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      siz[x]+=siz[y];
    }
    else{
      p[x]=y;
      siz[y]+=siz[x];
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int findSet(int x){
    if(x != p[x]) p[x]=findSet(p[x]);
    return p[x];
  }
  
  int size(int x){
    return siz[findSet(x)];
  }
};

vector<int> G[100010];

int main(){
  ll n,m,q;
  cin>>n>>m>>q;
  
  Dis ds=Dis(7*n);
  
  vector<string> A(n);
  rep(i,n) cin>>A[i];
  
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  
  rep(i,n){
    rep(j,6){
      if(A[i][j]=='1' && A[i][j+1]=='1') ds.unite(7*i+j,7*i+j+1);
    }
    if(A[i][0]=='1' && A[i][6]=='1') ds.unite(7*i,7*i+6);
  }
  
  rep(i,n){
    rep(j,7){
      for(auto t:G[i]){
        if(A[i][j]=='1' && A[t][j]=='1') ds.unite(7*i+j,7*t+j);
      }
    }
  }
  
  rep(i,q){
    int c,x,y;
    cin>>c>>x>>y;
    x--,y--;
    if(c==1){
      A[x][y]='1';
      if(A[x][(y+1)%7]=='1') ds.unite(7*x+y,7*x+(y+1)%7);
      if(A[x][(y+6)%7]=='1') ds.unite(7*x+y,7*x+(y+6)%7);
      for(auto t:G[x]){
        if(A[t][y]=='1') ds.unite(7*t+y,7*x+y);
      }
    }
    if(c==2){
      cout<<ds.size(7*x)<<endl;
    }
  }

  return 0;
}
0