結果

問題 No.1266 7 Colors
ユーザー chocono2230chocono2230
提出日時 2020-10-23 23:23:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 395 ms / 3,000 ms
コード長 2,014 bytes
コンパイル時間 4,458 ms
コンパイル使用メモリ 264,320 KB
実行使用メモリ 89,396 KB
最終ジャッジ日時 2023-09-28 18:37:39
合計ジャッジ時間 12,410 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 271 ms
10,328 KB
testcase_04 AC 373 ms
19,980 KB
testcase_05 AC 273 ms
12,060 KB
testcase_06 AC 386 ms
19,940 KB
testcase_07 AC 395 ms
19,868 KB
testcase_08 AC 370 ms
19,948 KB
testcase_09 AC 340 ms
19,152 KB
testcase_10 AC 326 ms
18,464 KB
testcase_11 AC 289 ms
14,276 KB
testcase_12 AC 312 ms
16,020 KB
testcase_13 AC 311 ms
17,080 KB
testcase_14 AC 272 ms
11,772 KB
testcase_15 AC 390 ms
20,024 KB
testcase_16 AC 311 ms
16,232 KB
testcase_17 AC 391 ms
20,188 KB
testcase_18 AC 328 ms
14,828 KB
testcase_19 AC 269 ms
89,316 KB
testcase_20 AC 264 ms
89,396 KB
testcase_21 AC 219 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
#include <atcoder/all>
using namespace atcoder;

void dfs(const vector<string> &s, const vector<vector<int>> &gr, int now, int color, dsu &d){
  int bfc = (color - 1 + 7) % 7, nxc = (color + 1) % 7;
  if(s.at(now).at(bfc) == '1' && d.same(now*7+color, now*7+bfc) == false){
    d.merge(now*7+color, now*7+bfc);
    dfs(s, gr, now, bfc, d);
  }
  if(s.at(now).at(nxc) == '1' && d.same(now*7+color, now*7+nxc) == false){
    d.merge(now*7+color, now*7+nxc);
    dfs(s, gr, now, nxc, d);
  }
  for(auto nx : gr.at(now)){
    if(s.at(nx).at(color) == '1' && d.same(now*7+color, nx*7+color) == false){
      d.merge(now*7+color, nx*7+color);
      dfs(s, gr, nx, color, d);
    }
  }
}

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  vector<vector<int>> gr(n, vector<int>());
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    gr.at(a).push_back(b);
    gr.at(b).push_back(a);
  }
  dsu d(n*7);
  rep(i, n){
    rep(j, 7){
      if(s.at(i).at(j) == '1'){
        dfs(s, gr, i, j, d);
      }
    }
  }
rep(iq, q){
  int mode, x, y;
  cin >> mode >> x >> y;
  x--; y--;
  if(mode == 1){
    s.at(x).at(y) = '1';
    int nxc = (y+1) % 7, bfc = (y-1+7) % 7;
    if(s.at(x).at(nxc) == '1'){
      d.merge(x*7+y, x*7+nxc);
    }
    if(s.at(x).at(bfc) == '1'){
      d.merge(x*7+y, x*7+bfc);
    }
    for(auto nx : gr.at(x)){
      if(s.at(nx).at(y) == '1'){
        d.merge(x*7+y, nx*7+y);
      }
    }
  }else{
    cout << d.size(x*7) << endl;
  }
}
  return 0;
}
0