結果

問題 No.1266 7 Colors
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-10-24 03:56:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,929 bytes
コンパイル時間 1,700 ms
コンパイル使用メモリ 173,504 KB
実行使用メモリ 11,748 KB
最終ジャッジ日時 2023-09-28 20:06:04
合計ジャッジ時間 6,057 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.10.24 03:56:10
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par.resize(n, -1);
    }
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    int n,m,q;cin >> n >> m >> q;
    vector<vector<int>> g(n);
    vector<string> s(n);
    UnionFind uf(7*n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        for (int j = 0; j < 7; j++) {
            if (s[i][j] == '0' || s[i][(j+1)%7] == '0') continue;
            uf.unite(n*i+j,n*i+(j+1)%7);
        }
    }
    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] == '0' || s[v][j] == '0') continue;
            uf.unite(n*u+j,n*v+j);
        }
    }
    while(q--) {
        int t,x,y;cin >> t >> x >> y;
        x--;y--;
        if (t == 1) {
            s[x][y] = '1';
            if (s[x][(y+6)%7] == '1') uf.unite(n*x+y,n*x+(y+6)%7);
            if (s[x][(y+1)%7] == '1') uf.unite(n*x+y,n*x+(y+1)%7);
            for (int i = 0; i < g[x].size(); i++) {
                if (s[g[x][i]][y] == '0') continue;
                uf.unite(n*x+y,n*g[x][i]+y);
            }
        }
        else {
            cout << uf.size(n*x) << endl;
        }
    }
    return 0;
}
0