結果

問題 No.1266 7 Colors
ユーザー chocoruskchocorusk
提出日時 2020-10-23 22:27:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 3,000 ms
コード長 2,081 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 131,560 KB
実行使用メモリ 17,560 KB
最終ジャッジ日時 2023-09-28 16:30:32
合計ジャッジ時間 8,555 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,820 KB
testcase_01 AC 4 ms
8,884 KB
testcase_02 AC 5 ms
8,824 KB
testcase_03 AC 252 ms
10,840 KB
testcase_04 AC 323 ms
14,504 KB
testcase_05 AC 260 ms
11,068 KB
testcase_06 AC 331 ms
15,132 KB
testcase_07 AC 339 ms
16,092 KB
testcase_08 AC 329 ms
14,920 KB
testcase_09 AC 315 ms
13,560 KB
testcase_10 AC 303 ms
13,144 KB
testcase_11 AC 270 ms
11,760 KB
testcase_12 AC 283 ms
12,156 KB
testcase_13 AC 284 ms
12,616 KB
testcase_14 AC 253 ms
11,064 KB
testcase_15 AC 344 ms
16,448 KB
testcase_16 AC 281 ms
12,220 KB
testcase_17 AC 339 ms
15,860 KB
testcase_18 AC 264 ms
17,560 KB
testcase_19 AC 157 ms
17,240 KB
testcase_20 AC 158 ms
16,936 KB
testcase_21 AC 225 ms
9,784 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0