結果
| 問題 | No.1266 7 Colors |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-24 00:42:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,272 bytes |
| 記録 | |
| コンパイル時間 | 2,236 ms |
| コンパイル使用メモリ | 201,400 KB |
| 最終ジャッジ日時 | 2025-01-15 14:47:14 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 14 |
ソースコード
// g++ A.cpp -std=c++14 -I . && ./a.out
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll INF = 1e18;
// 変数定義
int N, M, Q, a, b, c, d, e, x, y, t, T, total, cnt, ans;
class disjoint_set
{
public:
disjoint_set(int n) : par(n, -1) {}
void merge(int x, int y)
{
x = root(x);
y = root(y);
if (x == y)
return;
if (par[x] > par[y])
swap(x, y);
par[x] += par[y];
par[y] = x;
}
bool same(int x, int y) { return root(x) == root(y); }
int root(int x)
{
if (par[x] < 0)
return x;
return par[x] = root(par[x]);
}
int sizeOf(int x) { return -par[root(x)]; }
private:
vector<int> par;
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> Q;
disjoint_set uf(N * 7);
vector<string> S(N);
rep(i, N)
{
cin >> S[i];
rep(j, 7)
{
if (S[i][j] == '1' && S[i][(j + 1) % 7] == '1')
{
uf.merge(i * 7 + j, i * 7 + (j + 1) % 7);
// cout << i * 7 + j << ' ' << i * 7 + (j + 1) % 7 << '\n';
}
}
}
vector<vector<int>> edge(N);
rep(i, M)
{
cin >> x >> y;
x--;
y--;
edge[x].push_back(y);
edge[y].push_back(x);
rep(j, 7)
{
if (S[x][j] == '1' && S[y][j] == '1')
{
uf.merge(x * 7 + j, y * 7 + j);
// cout << x * 7 + j << ' ' << y * 7 + j << '\n';
}
}
}
rep(i, Q)
{
cin >> t >> a >> b;
a--;
b--;
if (t == 1)
{
S[a][b] = '1';
if (S[a][abs((b - 1) % 7)] == '1')
{
uf.merge(a * 7 + abs((b - 1) % 7), a * 7 + b);
// cout << a * 7 + abs((b - 1) % 7) << ' ' << a * 7 + b << '\n';
}
if (S[a][(b + 1) % 7] == '1')
{
uf.merge(a * 7 + (b + 1) % 7, a * 7 + b);
// cout << a * 7 + ((b + 1) % 7) << ' ' << a * 7 + b << '\n';
}
for (int v : edge[a])
{
if (S[v][b] == '1')
{
uf.merge(a * 7 + b, v * 7 + b);
// cout << a * 7 + b << ' ' << v * 7 + b << '\n';
}
}
}
else
{
cout << uf.sizeOf(a * 7) << '\n';
}
}
return 0;
}