結果

問題 No.1266 7 Colors
ユーザー hamrayhamray
提出日時 2020-11-11 17:24:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 219 ms / 3,000 ms
コード長 3,732 bytes
コンパイル時間 2,941 ms
コンパイル使用メモリ 157,228 KB
実行使用メモリ 18,324 KB
最終ジャッジ日時 2023-09-30 00:35:38
合計ジャッジ時間 7,308 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 203 ms
6,208 KB
testcase_04 AC 214 ms
13,572 KB
testcase_05 AC 198 ms
6,776 KB
testcase_06 AC 212 ms
14,596 KB
testcase_07 AC 219 ms
16,368 KB
testcase_08 AC 208 ms
13,740 KB
testcase_09 AC 196 ms
11,288 KB
testcase_10 AC 196 ms
10,424 KB
testcase_11 AC 195 ms
7,504 KB
testcase_12 AC 213 ms
8,556 KB
testcase_13 AC 193 ms
9,372 KB
testcase_14 AC 199 ms
6,728 KB
testcase_15 AC 213 ms
16,696 KB
testcase_16 AC 195 ms
8,848 KB
testcase_17 AC 210 ms
15,880 KB
testcase_18 AC 194 ms
18,324 KB
testcase_19 AC 84 ms
17,928 KB
testcase_20 AC 83 ms
17,948 KB
testcase_21 AC 167 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).endf()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).endf(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).endf())
#define SORT(c) sort((c).begin(), (c).endf())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-4, PI = acos(-1);
//ここから編集    
typedef string::const_iterator State;

struct UnionFind{
  vector<int> par;
  vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
    int N, M, Q; cin >> N >> M >> Q;
    vector<string> s(N);
    UnionFind uf(N*8);
    REP(i,N){
        cin >> s[i];
        int mask = 0;
        for(int j=0; j<7; j++){
            if(s[i][j] == '1' && s[i][(j+1)%7] == '1'){
                uf.merge(i*7+j, i*7+(j+1)%7);
            }
        }
    }
    vector<vector<int>> g(N);
    REP(i,M){
        int u, v; cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    
    REP(v,N){
        for(auto u: g[v]){
            for(int i=0; i<7; i++){
                if(s[v][i] == '1' && s[u][i] == '1'){
                    uf.merge(v*7+i, u*7+i);
                }
            }
        }
    }
    REP(i,Q){
        int q; cin >> q;
        if(q == 1){
            int x, y; cin >> x >> y;
            x--;
            y--;
            s[x][y] = '1';
            for(auto u: g[x]){
                for(int j=0; j<7; j++){
                    if(s[x][j]=='1' && s[u][j]=='1'){
                        uf.merge(x*7+j, u*7+j);
                    }
                }
            }
            for(int j=0; j<7; j++){
                if(s[x][j]=='1' && s[x][(j+1)%7]=='1'){
                    uf.merge(x*7+j, x*7+(j+1)%7);
                }
            }
        }else{
            int x, t; cin >> x >> t;
            x--;
            cout << uf.size(x*7) << endl;
        }
    }
    return 0;
}
0