codeforces: 1003
This commit is contained in:
parent
7440bc2937
commit
d1b961e1c4
60 changed files with 2235 additions and 0 deletions
9
codeforces/1003/.clang-format
Normal file
9
codeforces/1003/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: Google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
8
codeforces/1003/.clangd
Normal file
8
codeforces/1003/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -std=c++23
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -Wno-unknown-pragmas
|
||||
79
codeforces/1003/a.cc
Normal file
79
codeforces/1003/a.cc
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T> constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T> constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T> [[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args> void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args> void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() { std::println(); }
|
||||
|
||||
void prln(auto const &t) { std::println("{}", t); }
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T> using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
for (int i = 0; i < s.size() - 2; ++i) {
|
||||
cout << s[i];
|
||||
}
|
||||
cout << "i\n";
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
10
codeforces/1003/a.in
Normal file
10
codeforces/1003/a.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
9
|
||||
us
|
||||
sus
|
||||
fungus
|
||||
cactus
|
||||
sussus
|
||||
amogus
|
||||
chungus
|
||||
ntarsus
|
||||
skibidus
|
||||
12
codeforces/1003/a.out
Normal file
12
codeforces/1003/a.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
i
|
||||
si
|
||||
fungi
|
||||
cacti
|
||||
sussi
|
||||
amogi
|
||||
chungi
|
||||
ntarsi
|
||||
skibidi
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.63152 ms
|
||||
102
codeforces/1003/b.cc
Normal file
102
codeforces/1003/b.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
vec<char> S;
|
||||
for (auto e : s) {
|
||||
if (!S.empty() && S.back() == e) {
|
||||
S.pop_back();
|
||||
S.push_back('*');
|
||||
} else
|
||||
S.push_back(e);
|
||||
}
|
||||
|
||||
while (sz<int>(S) >= 2) {
|
||||
if (S.back() == '*' || S[sz<int>(S) - 1] == '*')
|
||||
S.pop_back();
|
||||
else
|
||||
break;
|
||||
}
|
||||
prln("{}", sz<int>(S));
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
5
codeforces/1003/b.in
Normal file
5
codeforces/1003/b.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
baa
|
||||
skibidus
|
||||
cc
|
||||
ohio
|
||||
7
codeforces/1003/b.out
Normal file
7
codeforces/1003/b.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
1
|
||||
8
|
||||
1
|
||||
4
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.9956 ms
|
||||
106
codeforces/1003/c.cc
Normal file
106
codeforces/1003/c.cc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
vec<int> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
int x;
|
||||
cin >> x;
|
||||
|
||||
a[0] = min(a[0], x - a[0]);
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (a[i] >= a[i - 1] && x - a[i] >= a[i - 1]) {
|
||||
a[i] = min(a[i], x - a[i]);
|
||||
} else if (a[i] >= a[i - 1]) {
|
||||
;
|
||||
} else if (x - a[i] >= a[i - 1]) {
|
||||
a[i] = x - a[i];
|
||||
} else {
|
||||
prln("NO");
|
||||
return;
|
||||
}
|
||||
}
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/1003/c.in
Normal file
16
codeforces/1003/c.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
1 1
|
||||
5
|
||||
9
|
||||
3 1
|
||||
1 4 3
|
||||
3
|
||||
4 1
|
||||
1 4 2 5
|
||||
6
|
||||
4 1
|
||||
5 4 10 5
|
||||
4
|
||||
3 1
|
||||
9 8 7
|
||||
8
|
||||
8
codeforces/1003/c.out
Normal file
8
codeforces/1003/c.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.0981 ms
|
||||
5
codeforces/1003/compile_flags.txt
Normal file
5
codeforces/1003/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-std=c++23
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
109
codeforces/1003/d.cc
Normal file
109
codeforces/1003/d.cc
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
ll n, m;
|
||||
cin >> n >> m;
|
||||
vec<vec<ll>> arrays(n, vec<ll>(m));
|
||||
vec<pair<ll, int>> scores;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
ll score = 0;
|
||||
for (auto& e : arrays[i]) {
|
||||
cin >> e;
|
||||
score += e;
|
||||
}
|
||||
scores.eb(score, i);
|
||||
}
|
||||
|
||||
sort(rall(scores));
|
||||
|
||||
ll ans = 0;
|
||||
ll x = n * m;
|
||||
for (int i = 0; i < sz<int>(scores); ++i) {
|
||||
int index = scores[i].ss;
|
||||
for (auto e : arrays[index]) {
|
||||
ans += e * x--;
|
||||
}
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/1003/d.in
Normal file
11
codeforces/1003/d.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
3
|
||||
2 2
|
||||
4 4
|
||||
6 1
|
||||
3 4
|
||||
2 2 2 2
|
||||
3 2 1 2
|
||||
4 1 2 1
|
||||
2 3
|
||||
3 4 5
|
||||
1 1 9
|
||||
6
codeforces/1003/d.out
Normal file
6
codeforces/1003/d.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
41
|
||||
162
|
||||
72
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.8089 ms
|
||||
86
codeforces/1003/e.cc
Normal file
86
codeforces/1003/e.cc
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
0
codeforces/1003/e.in
Normal file
0
codeforces/1003/e.in
Normal file
0
codeforces/1003/e.out
Normal file
0
codeforces/1003/e.out
Normal file
134
codeforces/1003/f.cc
Normal file
134
codeforces/1003/f.cc
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const &t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
vec<int> a(n + 1);
|
||||
for (int i = 1; i < sz<int>(a); ++i) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
vec<vec<int>> tree(n + 1, vec<int>());
|
||||
string ans(n, '0');
|
||||
|
||||
int root;
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
root = u;
|
||||
tree[u].pb(v);
|
||||
tree[v].pb(u);
|
||||
}
|
||||
|
||||
unordered_map<int, unordered_map<int, int>> children;
|
||||
vec<int> par(n + 1, -1);
|
||||
par[root] = root;
|
||||
|
||||
queue<int> q{{root}};
|
||||
|
||||
while (!q.empty()) {
|
||||
int size = sz<int>(q);
|
||||
while (size--) {
|
||||
auto u = q.front();
|
||||
q.pop();
|
||||
for (auto v : tree[u]) {
|
||||
if (par[v] != -1)
|
||||
continue;
|
||||
par[v] = u;
|
||||
q.push(v);
|
||||
if (++children[u][a[v]] == 2)
|
||||
ans[a[v] - 1] = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
q.push(root);
|
||||
|
||||
for (int u = 1; u <= n; ++u) {
|
||||
if (par[u] != u && a[u] == a[par[u]] ||
|
||||
par[u] != root && a[u] == a[par[par[u]]])
|
||||
ans[a[u] - 1] = '1';
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
29
codeforces/1003/f.in
Normal file
29
codeforces/1003/f.in
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
4
|
||||
3
|
||||
1 2 3
|
||||
1 3
|
||||
2 3
|
||||
4
|
||||
3 1 1 3
|
||||
1 2
|
||||
2 3
|
||||
4 2
|
||||
4
|
||||
2 4 4 2
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
13
|
||||
1 4 4 7 4 7 1 1 7 11 11 11 11
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
4 5
|
||||
4 6
|
||||
2 7
|
||||
7 8
|
||||
2 9
|
||||
6 10
|
||||
5 11
|
||||
11 12
|
||||
10 13
|
||||
7
codeforces/1003/f.out
Normal file
7
codeforces/1003/f.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
000
|
||||
1010
|
||||
0001
|
||||
1001001000100
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.66259 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue