結果

問題 No.1266 7 Colors
ユーザー otera
提出日時 2020-10-24 00:49:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 217 ms / 3,000 ms
コード長 3,730 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 134,500 KB
最終ジャッジ日時 2025-01-15 14:47:50
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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

/**
* author: otera
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<array>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct UnionFind {
vector<int> par, w;
UnionFind(int n) : par(n, -1), w(n, 0) { }
void init(int n) { par.assign(n, -1); w.assign(n, 0); }
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) {
++w[x];
return false;
}
if (par[x] > par[y]) swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
w[x] += w[y];
++w[x];
return true;
}
int size(int x) {
return -par[root(x)];
}
int wei(int x) {
return w[root(x)];
}
};
void solve() {
int n, m, q; cin >> n >> m >> q;
UnionFind uf(7 * n);
vector<string> s(n);
rep(i, n) {
cin >> s[i];
rep(j, 7) {
if(s[i][j] == '1' and s[i][(j + 1) % 7] == '1') {
uf.merge(i + j * n, i + (j + 1) % 7 * n);
}
if(s[i][j] == '1' and s[i][(j + 6) % 7] == '1') {
uf.merge(i + j * n, i + (j + 6) % 7 * n);
}
}
}
vector<vector<int>> g(n, vector<int>());
rep(i, m) {
int u, v; cin >> u >> v; -- u, -- v;
g[u].push_back(v);
g[v].push_back(u);
rep(j, 7) {
if(s[u][j] == '1' and s[v][j] == '1') {
uf.merge(u + j * n, v + j * n);
}
}
}
rep(_, q) {
int t; cin >> t;
if(t == 1) {
int x, y; cin >> x >> y; -- x, -- y;
s[x][y] = '1';
if(s[x][(y + 1) % 7] == '1') {
uf.merge(x + y * n, x + ((y + 1) % 7) * n);
}
if(s[x][(y - 1 + 7) % 7] == '1') {
uf.merge(x + y * n, x + ((y + 6) % 7) * n);
}
for(int nx: g[x]) {
if(s[nx][y] == '1') {
uf.merge(x + y * n, nx + y * n);
}
}
} else {
int x, y; cin >> x >> y; -- x;
cout << uf.size(x) << endl;
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//int t; cin >> t; rep(i, t)solve();
solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0