Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- bool way(pii a, pii b) {
- return a.first == b.first || a.second == b.second || abs(a.first - b.first) == abs(a.second - b.second);
- }
- vector <int> clr, tocomp, compsz;
- vector <vector <int> > G;
- int n;
- void dfs(int v, int comp) {
- tocomp[v] = comp;
- clr[v] = 1;
- for (int u: G[v]) {
- if (clr[u] == 0) {
- dfs(u, comp);
- }
- }
- clr[v] = 2;
- }
- bool sh = 0;
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- string q; cin >> q;
- pii str = {q[1] - '0' - 1, q[0] - 'A'};
- vector <pii> pwn(n);
- for (int i = 0; i < n; ++i) {
- string s; cin >> s;
- pwn[i] = {s[1] - '0' - 1, s[0] - 'A'};
- }
- G.resize(n);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n && j != i; ++j) {
- if (way(pwn[i], pwn[j])) {
- G[i].pb(j);
- G[j].pb(i);
- }
- }
- }
- if (sh) {
- cout << "pwn\n";
- cvp(pwn);
- cout << "G\n";
- cvv(G);
- }
- int cnt = -1;
- clr.assign(n, 0);
- tocomp.assign(n, -1);
- for (int i = 0; i < n; ++i) {
- if (clr[i] == 0) {
- cnt++;
- dfs(i, cnt);
- }
- }
- vector <int> compsz(cnt + 1);
- for (int i = 0; i <= cnt; ++i) {
- compsz[i] = count(tocomp.begin(), tocomp.end(), i);
- }
- int ans = 0, bst = -1;
- for (int i = 0; i < n; ++i) {
- if (compsz[ tocomp[i] ] > ans) {
- bst = tocomp[i];
- ans = compsz[ tocomp[i] ];
- }
- }
- cout << ans << "\n";
- if (sh) {
- cout << "clr\n";
- cv(clr);
- cout << "tocomp\n";
- cv(tocomp);
- cout << "compsz\n";
- cv(compsz);
- cout << "bst = " << bst << "\n";
- }
- for (int i = 0; i < n; ++i) {
- if (tocomp[i] == bst) {
- if (sh) {
- cout << pwn[i].first << ' '<< pwn[i].second << "\n";
- }
- cout << char( 'A' + (pwn[i].second )) << (pwn[i].first + 1) << "\n";
- }
- }
- }
- /*
- 11 A1
- A8
- G7
- F5
- F4
- F3
- F2
- F1
- E3
- E2
- D3
- D2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement