Add a bunch of other problems.
Some are not finished...
This commit is contained in:
140
Codeforces Round 1023 (Div. 2)/A. LRC and VIP.cpp
Normal file
140
Codeforces Round 1023 (Div. 2)/A. LRC and VIP.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2107/problem/A */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vi fds(n);
|
||||
cin >> fds;
|
||||
|
||||
vi pref(n);
|
||||
vi suf(n);
|
||||
|
||||
pref[0] = fds[0];
|
||||
suf.back() = fds.back();
|
||||
|
||||
nrep(i, 1, n) {
|
||||
pref[i] = __gcd(pref[i - 1], fds[i]);
|
||||
suf[n - i - 1] = __gcd(suf[n - i], fds[n - i - 1]);
|
||||
}
|
||||
|
||||
if (fds[0] != suf[1]) {
|
||||
cout << "Yes\n";
|
||||
cout << "1";
|
||||
nrep(i, 1, n) {
|
||||
cout << " 2";
|
||||
}
|
||||
cout << '\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fds[n - 1] != pref[n - 2]) {
|
||||
cout << "Yes\n";
|
||||
rep(i, n - 1) {
|
||||
cout << "1 ";
|
||||
}
|
||||
cout << "2\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
int choice = -1;
|
||||
nrep(i, 1, n - 1) {
|
||||
int act = __gcd(pref[i - 1], suf[i + 1]);
|
||||
if (act != fds[i]) {
|
||||
choice = i;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (choice != -1) {
|
||||
cout << "Yes\n";
|
||||
rep(i, choice) {
|
||||
cout << "1 ";
|
||||
}
|
||||
cout << "2";
|
||||
nrep(i, choice + 1, n) {
|
||||
cout << " 1";
|
||||
}
|
||||
cout << "\n";
|
||||
} else {
|
||||
cout << "No\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
108
Codeforces Round 1023 (Div. 2)/B. Apples in Boxes.cpp
Normal file
108
Codeforces Round 1023 (Div. 2)/B. Apples in Boxes.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2107/problem/B */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vi fds(n);
|
||||
int minimal = INT32_MAX;
|
||||
int maximal = 0;
|
||||
int prev = 0;
|
||||
ll total = 0;
|
||||
|
||||
repv(i, fds) {
|
||||
cin >> i;
|
||||
|
||||
rmin(minimal, i);
|
||||
if (i >= maximal) {
|
||||
prev = maximal;
|
||||
maximal = i;
|
||||
}
|
||||
|
||||
total += i;
|
||||
}
|
||||
|
||||
if (max(maximal - 1, prev) - minimal > k || total % 2 == 0) {
|
||||
cout << "Jerry\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "Tom\n";
|
||||
}
|
||||
}
|
||||
173
Codeforces Round 1023 (Div. 2)/C. Maximum Subarray Sum.cpp
Normal file
173
Codeforces Round 1023 (Div. 2)/C. Maximum Subarray Sum.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2107/problem/C */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
ll inf = 1e17;
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
ll k;
|
||||
cin >> n >> k;
|
||||
|
||||
string a;
|
||||
cin >> a;
|
||||
|
||||
vl fds(n);
|
||||
rep(i, n) {
|
||||
cin >> fds[i];
|
||||
if (a[i] == '0') {
|
||||
fds[i] = -inf;
|
||||
}
|
||||
}
|
||||
|
||||
if (n == 1) {
|
||||
if (a[0] == '0') {
|
||||
fds[0] = k;
|
||||
}
|
||||
|
||||
if (fds[0] == k) {
|
||||
cout << "Yes\n" << k << "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "No\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
ll total = 0;
|
||||
ll maximus = 0;
|
||||
rep(i, n) {
|
||||
total += fds[i];
|
||||
rmax(total, 0LL);
|
||||
rmax(maximus, total);
|
||||
}
|
||||
|
||||
if (maximus > k) {
|
||||
cout << "No\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (maximus == k) {
|
||||
cout << "Yes\n";
|
||||
cout << fds;
|
||||
continue;
|
||||
}
|
||||
|
||||
vl pref(n);
|
||||
vl suf(n);
|
||||
|
||||
pref[0] = fds[0];
|
||||
suf.back() = fds.back();
|
||||
nrep(i, 1, n) {
|
||||
pref[i] = max(fds[i], fds[i] + pref[i - 1]);
|
||||
suf[n - i - 1] = max(fds[n - i - 1], fds[n - i - 1] + suf[n - i]);
|
||||
}
|
||||
|
||||
|
||||
if (suf[1] <= k && a[0] == '0') {
|
||||
cout << "Yes\n";
|
||||
fds[0] = k - max(suf[1], 0LL);
|
||||
cout << fds;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pref[n - 2] <= k && a[n - 1] == '0') {
|
||||
cout << "Yes\n";
|
||||
fds[n - 1] = k - max(pref[n - 2], 0LL);
|
||||
cout << fds;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool pos = false;
|
||||
nrep(i, 1, n - 1) {
|
||||
if (a[i] == '0') {
|
||||
pos = true;
|
||||
fds[i] = k - (max(pref[i - 1], 0LL) + max(suf[i + 1], 0LL));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos) {
|
||||
cout << "Yes\n";
|
||||
cout << fds;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "No\n";
|
||||
}
|
||||
}
|
||||
344
Codeforces Round 1023 (Div. 2)/D. Apple Tree Traversing.cpp
Normal file
344
Codeforces Round 1023 (Div. 2)/D. Apple Tree Traversing.cpp
Normal file
@@ -0,0 +1,344 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2107/problem/D */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
#define MAX_N 150000
|
||||
|
||||
vvi graph;
|
||||
int inf = INT32_MAX >> 1;
|
||||
int n;
|
||||
int parent[MAX_N];
|
||||
int vis[MAX_N];
|
||||
int dis[MAX_N];
|
||||
queue<int> used;
|
||||
|
||||
V<tuple<int, int, int>> ans;
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
fill(dis, dis + MAX_N, inf);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
cin >> n;
|
||||
graph.assign(n, vi());
|
||||
fill(vis, vis + n, inf);
|
||||
|
||||
rep(i, n - 1) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
a--, b--;
|
||||
|
||||
graph[a].push_back(b);
|
||||
graph[b].push_back(a);
|
||||
}
|
||||
|
||||
ans.clear();
|
||||
|
||||
function<void(int, int)> solve = [&solve](int i, int t){
|
||||
int diam;
|
||||
|
||||
auto getcenter = [&](int i) {
|
||||
int inf = INT32_MAX;
|
||||
|
||||
auto bfs = [&](int i) {
|
||||
dis[i] = 0;
|
||||
used.push(i);
|
||||
|
||||
int ans = i;
|
||||
|
||||
queue<int> q;
|
||||
q.push(i);
|
||||
|
||||
while (!q.empty()) {
|
||||
int i = q.front();
|
||||
q.pop();
|
||||
|
||||
for (auto j : graph[i]) {
|
||||
if (vis[j] >= t && dis[j] > dis[i] + 1) {
|
||||
used.push(j);
|
||||
dis[j] = dis[i] + 1;
|
||||
ans = j;
|
||||
parent[j] = i;
|
||||
q.push(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
int now = bfs(i);
|
||||
while (!used.empty()) {
|
||||
dis[used.front()] = inf;
|
||||
used.pop();
|
||||
}
|
||||
now = bfs(now);
|
||||
diam = dis[now] + 1;
|
||||
|
||||
while (!used.empty()) {
|
||||
dis[used.front()] = inf;
|
||||
used.pop();
|
||||
}
|
||||
|
||||
rep(i, diam / 2) {
|
||||
now = parent[now];
|
||||
}
|
||||
|
||||
return now;
|
||||
};
|
||||
|
||||
int center = getcenter(i);
|
||||
|
||||
if (diam == 1) {
|
||||
ans.emplace_back(diam, i, i);
|
||||
vis[i] = t;
|
||||
return;
|
||||
}
|
||||
|
||||
if (diam == 2) {
|
||||
int other = parent[center];
|
||||
|
||||
if (other < center) {
|
||||
swap(other, center);
|
||||
}
|
||||
|
||||
vis[other] = t;
|
||||
vis[center] = t;
|
||||
|
||||
ans.emplace_back(diam, other, center);
|
||||
return;
|
||||
}
|
||||
|
||||
function<void(int, int)> setvis = [&](int x, int y) {
|
||||
int now = x;
|
||||
while (now != -1) {
|
||||
vis[now] = t;
|
||||
now = parent[now];
|
||||
}
|
||||
|
||||
now = y;
|
||||
while (now != -1) {
|
||||
vis[now] = t;
|
||||
now = parent[now];
|
||||
}
|
||||
};
|
||||
|
||||
function<void(int, int)> iamtiredmaster = [&](int i, int p) {
|
||||
for (auto j : graph[i]) {
|
||||
if (j == p) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vis[j] < t) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vis[j] == t) {
|
||||
iamtiredmaster(j, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
solve(j, t + 1);
|
||||
}
|
||||
};
|
||||
|
||||
if (diam % 2 == 0) {
|
||||
function<pair<int, int>(int, int, int)> dfs = [&](int i, int p, int d) {
|
||||
bool leaf = true;
|
||||
parent[i] = p;
|
||||
|
||||
pair<int, int> ans = {-1, -1};
|
||||
|
||||
for (auto j : graph[i]) {
|
||||
if (vis[j] < t || j == p) {
|
||||
continue;
|
||||
}
|
||||
|
||||
leaf = false;
|
||||
pair<int, int> tmp = dfs(j, i, d + 1);
|
||||
|
||||
rmax(ans.first, tmp.first);
|
||||
rmax(ans.second, tmp.second);
|
||||
}
|
||||
|
||||
if (leaf) {
|
||||
if (d == diam / 2) {
|
||||
ans.first = i;
|
||||
} else if (d == diam / 2 - 1) {
|
||||
ans.second = i;
|
||||
}
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
pair<int, int> prev = {-1, -1};
|
||||
pair<int, int> final = {0, 0};
|
||||
|
||||
for (auto j : graph[center]) {
|
||||
if (vis[j] < t) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pair<int, int> tmp = dfs(j, center, 1);
|
||||
pair<int, int> cont1 = {tmp.first, prev.second};
|
||||
pair<int, int> cont2 = {tmp.second, prev.first};
|
||||
|
||||
if (cont1.first < cont1.second) {
|
||||
swap(cont1.first, cont1.second);
|
||||
}
|
||||
|
||||
if (cont1.second == -1) {
|
||||
cont1 = {-1, -1};
|
||||
}
|
||||
|
||||
if (cont2.first < cont2.second) {
|
||||
swap(cont2.first, cont2.second);
|
||||
}
|
||||
|
||||
if (cont2.second == -1) {
|
||||
cont2 = {-1, -1};
|
||||
}
|
||||
|
||||
rmax(prev.first, tmp.first);
|
||||
rmax(prev.second, tmp.second);
|
||||
|
||||
rmax(final, cont1);
|
||||
rmax(final, cont2);
|
||||
}
|
||||
|
||||
ans.emplace_back(diam, final.first, final.second);
|
||||
parent[center] = -1;
|
||||
|
||||
vis[center] = t;
|
||||
setvis(final.first, final.second);
|
||||
iamtiredmaster(center, center);
|
||||
return;
|
||||
}
|
||||
|
||||
function<int(int, int, int)> dfs = [&](int i, int p, int d) {
|
||||
parent[i] = p;
|
||||
if (d == diam / 2) {
|
||||
return i;
|
||||
}
|
||||
|
||||
int ans = -1;
|
||||
|
||||
for (auto j : graph[i]) {
|
||||
if (vis[j] < t || j == p) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rmax(ans, dfs(j, i, d + 1));
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
priority_queue<int, vi, greater<>> fds;
|
||||
fds.push(0);
|
||||
fds.push(0);
|
||||
|
||||
for (auto j : graph[center]) {
|
||||
if (vis[j] < t) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fds.push(dfs(j, center, 1));
|
||||
fds.pop();
|
||||
}
|
||||
|
||||
pair<int, int> tmp;
|
||||
tmp.second = fds.top();
|
||||
fds.pop();
|
||||
tmp.first = fds.top();
|
||||
|
||||
ans.emplace_back(diam, tmp.first, tmp.second);
|
||||
|
||||
vis[center] = t;
|
||||
parent[center] = -1;
|
||||
setvis(tmp.first, tmp.second);
|
||||
iamtiredmaster(center, center);
|
||||
};
|
||||
|
||||
solve(0, 0);
|
||||
|
||||
sort(all(ans), greater<>());
|
||||
for (auto [diam, x, y] : ans) {
|
||||
cout << diam << ' ' << x + 1 << ' ' << y + 1 << ' ';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user