結果

問題 No.1266 7 Colors
ユーザー milanis48663220
提出日時 2020-10-23 22:35:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 2,066 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 88,768 KB
実行使用メモリ 11,544 KB
最終ジャッジ日時 2024-07-21 11:24:57
合計ジャッジ時間 5,412 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other RE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) { }
bool unionSet(int x, int y) {
x = root(x); y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
int n, m, q;
string s[100000];
vector<int> G[100000];
int to_idx(int i, int col){
return i*n+col;
}
UnionFind uf(0);
void input(){
cin >> n >> m >> q;
uf = UnionFind(n*7);
for(int i = 0; i < n; i++) cin >> s[i];
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 col = 0; col < 7; col++){
if(s[u][col] == '1' && s[v][col] == '1'){
uf.unionSet(to_idx(u, col), to_idx(v, col));
}
}
}
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.unionSet(to_idx(i, j), to_idx(i, (j+1)%7));
}
}
}
}
void solve(){
int t, x, y; cin >> t >> x >> y; x--; y--;
if(t == 1){
int nx = (y+1)%7;
int pre = (y+6)%7;
s[x][y] = '1';
if(s[x][pre] == '1') uf.unionSet(to_idx(x, pre), to_idx(x, y));
if(s[x][nx] == '1') uf.unionSet(to_idx(x, nx), to_idx(x, y));
for(int to : G[x]){
if(s[to][y] == '1'){
uf.unionSet(to_idx(x, y), to_idx(to, y));
}
}
}else{
cout << uf.size(to_idx(x, 0)) << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
input();
for(int i = 0; i < q; i++) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0