text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a1 = 0, a2 = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
int w;
cin >> w;
if (w == 100)
++a1;
else
++a2;
}
if (a1 % 2 != 0 || (a2 % 2 != 0 && a1 == 0))
cout << "NO"
<< "\n";
else
cout << "YES"
<< "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int w[101];
int k = 0;
int s = 0;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &w[i]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (w[i] > w[j]) {
int tmp = w[i];
w[i] = w[j];
w[j] = tmp;
}
}
}
k = w[0];
for (int i = 1; i < n; i++) {
if (k < s)
k += w[i];
else
s += w[i];
}
if (k == s)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int GCD(int x, int y) {
if (x % y == 0)
return y;
else
return (GCD(y, x % y));
}
int main() {
int n, x;
int t = 0, o = 0, sum = 0;
scanf("%d", &x);
while (x--) {
scanf("%d", &n);
if (n == 100)
o++;
else
t++;
sum += n;
}
if (!o) {
if (t & 1) {
cout << "NO" << endl;
} else
cout << "YES" << endl;
} else if (!t) {
{
if (o & 1) {
cout << "NO" << endl;
} else
cout << "YES" << endl;
}
} else {
sum /= 2;
sum %= 200;
if (sum % 100 == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t[100003];
char res[4] = {'A', 'B', 'C', 'D'};
char C[300001];
char s[100004];
int B[100004];
int main() {
int n1 = 0;
int n2 = 0;
int sum = 0;
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int t;
scanf("%d", &t);
sum += t;
if (t == 100)
n1++;
else
n2++;
}
if (((sum / 100) % 2 == 0)) {
sum /= 200;
if (sum % 2 == 0)
puts("YES");
else if (n1 > 0 && (n1 % 2 == 0))
puts("YES");
else
puts("NO");
} else
puts("NO");
printf("%s\n", s);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
int count1 = 0, count2 = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (v[i] == 100)
count1++;
else
count2++;
}
if (count2 % 2 == 0) {
if (count1 % 2 == 0)
cout << "YES";
else
cout << "NO";
} else {
if (count1 % 2 == 0 && count1 >= 2)
cout << "YES";
else
cout << "NO";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, sum = 0, hun = 0, two = 0, t;
cin >> n;
if (n == 1)
cout << "NO";
else {
long long a[210];
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100)
hun++;
else
two++;
}
if (hun == 0) {
if (two % 2 == 0)
cout << "YES";
else
cout << "NO";
} else {
t = abs(hun - (2 * two));
if (t % 2 == 0)
cout << "YES";
else
cout << "NO";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int main() {
cin >> n;
while (cin >> n) {
if (n == 100)
a++;
else
b++;
}
if ((a % 2) || ((b % 2) && (!a)))
cout << "NO";
else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int two, one;
two = one = 0;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x == 100)
one++;
else
two++;
}
if (one % 2 == 1) {
cout << "NO\n";
} else if (two % 2 == 1) {
if (one >= 2)
cout << "YES\n";
else
cout << "NO\n";
} else
cout << "YES\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int n1 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100) {
n1++;
}
}
int n2 = n - n1;
if ((n1 & 1) == 1) {
cout << "NO";
} else if ((n2 & 1) == 0) {
cout << "YES";
} else if (n1 > 0) {
cout << "YES";
} else {
cout << "NO";
}
}
|
#include <bits/stdc++.h>
using namespace std;
void prob() {
int n;
cin >> n;
int tw = 0;
int hu = 0;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
if (k == 100) {
hu++;
} else {
tw++;
}
}
tw = tw % 2;
hu = hu - 2 * tw;
if (hu % 2 == 0 && hu >= 0) {
cout << "YES";
} else {
cout << "NO";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
while (t > 0) {
prob();
t--;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, one, two;
while (cin >> n) {
one = 0;
two = 0;
while (n--) {
cin >> x;
if (x == 100)
one++;
else
two++;
}
if (two % 2 == 0 && one % 2 == 0)
cout << "YES" << endl;
else if (two % 2 == 1 && one % 2 == 0 && one >= 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, a = 0, b = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &m);
if (m == 100) {
a++;
} else {
b++;
}
}
if (a == 0) {
if (b % 2 == 0) {
printf("YES");
} else {
printf("NO");
}
} else {
if (a % 2 == 0) {
printf("YES");
} else {
printf("NO");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double eps = 1e-9;
int main() {
int n;
cin >> n;
int c100 = 0, c200 = 0, temp;
for (int i = 0; i < n; i++) {
cin >> temp;
if (temp == 200) {
c200++;
} else {
c100++;
}
}
if (c200 == 0) {
if (c100 % 2 == 0) {
printf("YES\n");
return 0;
} else {
printf("NO\n");
return 0;
}
} else {
if (c100) {
if (c100 % 2 == 0) {
printf("YES\n");
return 0;
} else {
printf("NO\n");
return 0;
}
} else {
if (c200 % 2 == 0) {
printf("YES\n");
return 0;
}
}
}
printf("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0, ca = 0, cb = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x == 100)
++ca;
else
++cb;
sum += x;
}
if (sum % 2 == 1)
cout << "NO\n";
else {
bool ok = 0;
for (int i = 0; i <= ca; ++i)
for (int j = 0; j <= cb; ++j)
if (i * 100 + j * 200 == sum / 2) ok = 1;
if (ok)
cout << "YES\n";
else
cout << "NO\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[400];
int can[1000];
int main() {
int n;
scanf("%d", &n);
int s = 0;
can[0] = 1;
for (int i = 0; i < n; i++) {
int k;
scanf("%d", &k);
k /= 100;
s += k;
for (int t = 1000 - 1; t >= 0; t--)
if (can[t]) can[t + k] = 1;
}
if (s % 2)
puts("NO");
else {
int p = s / 2;
if (can[p])
puts("YES");
else
puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, k1, x, su(0), n, a(0), b(0), s1(0);
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x == 100)
a++;
else
b++;
su += x;
}
su /= 2;
if ((su / 50) & 1) {
cout << "NO";
return 0;
}
x = su / 200;
for (i = x; i >= 0; i--) {
k = i;
k1 = (su - (k * 200)) / 100;
if (k > b || k1 > a)
continue;
else {
if (((b - k) * 200 + (a - k1) * 100) == su) {
cout << "YES";
return 0;
} else
continue;
}
}
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
int n, num1, num2;
int i, j, k, w;
int flag;
int main() {
scanf("%d", &n);
num1 = num2 = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &j);
if (j == 100)
num1++;
else
num2++;
}
flag = 0;
for (i = 0; i <= num1; i++)
for (j = 0; j <= num2; j++) {
k = i * 100 + j * 200;
w = (num1 - i) * 100 + (num2 - j) * 200;
if (k == w) flag = 1;
}
if (flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool mycompare(pair<int, int> p1, pair<int, int> p2) {
return p1.first < p2.first;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
int a[n], n1 = 0, n2 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100)
n1 += 1;
else
n2 += 1;
}
if ((n1 % 2 == 0 && n1 != 0) || (n1 == 0 && n2 % 2 == 0))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int apples;
int cnt_100 = 0, cnt_200 = 0;
cin >> apples;
while (apples--) {
int weight;
cin >> weight;
if (weight == 100)
cnt_100++;
else
cnt_200++;
}
if (cnt_100 % 2 == 1) {
cout << "NO" << endl;
} else if (cnt_200 % 2 == 0) {
cout << "YES" << endl;
} else if (cnt_100 / 2 > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, sot = 0, dvus = 0, r;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> r;
if (r == 100)
sot++;
else
dvus++;
}
if (sot % 2) cout << "NO";
if (!(sot % 2) && !(dvus % 2)) cout << "YES";
if (!(sot % 2) && (dvus % 2)) {
if (sot < 2)
cout << "NO";
else
cout << "YES";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum[105];
int a[105];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i)
sum[i] = sum[i - 1] + a[i];
else
sum[i] = a[i];
}
int nn = sum[n - 1] / 2;
bool ok = false;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (sum[j] - sum[i] == nn) {
ok = true;
break;
}
}
}
if (sum[n - 1] & 1) ok = false;
if (ok)
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
long int n200, n100;
long int i, j;
using namespace std;
int main() {
long int n;
cin >> n;
long int i, x;
for (i = 1; i <= n; i++) {
cin >> x;
if (x == 100)
n100++;
else
n200++;
}
if (n100 % 2 == 0)
if (n200 % 2 == 0) {
cout << "YES";
return 0;
} else if (n100 >= 2) {
cout << "YES";
return 0;
} else {
cout << "NO";
return 0;
}
else {
cout << "NO";
return 0;
}
}
|
#include <bits/stdc++.h>
using namespace std;
inline void boost() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int n, h, th;
int main() {
boost();
cin >> n;
for (int i = 1, x; i <= n; i++) {
cin >> x;
if (x == 100)
h++;
else
th++;
}
if (th % 2 && h == 0)
cout << "NO";
else if ((th % 2 && h % 2) || (!(th % 2) && h % 2))
cout << "NO";
else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n;
int a[n + 1], ans = 0, x = 0, y = 0, l, m, k;
for (i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 100)
x++;
else
y++;
}
k = x * 100 + y * 200;
if (k % 200 == 0) {
if (x == 0 && y % 2 == 0)
cout << "YES";
else if (x != 0)
cout << "YES";
else
cout << "NO";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0, cnt2 = 0;
cin >> n;
int w;
for (int i = 0; i < n; i++) {
cin >> w;
if (w == 100) cnt++;
if (w == 200) cnt2++;
}
if (cnt == 0 && cnt2 % 2 != 0) {
cout << "NO";
return 0;
}
if (cnt % 2 == 0)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, i, x, t, o;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &x);
if (x == 200) t++;
}
o = n - t;
if (t & 1) o -= 2;
if (o < 0 || o & 1)
puts("NO");
else
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w, one = 0, two = 0;
cin >> n;
while (n--) {
cin >> w;
if (w == 100)
one++;
else
two++;
}
int weight = (one * 100) + (two * 200);
if (weight % 200 != 0)
cout << "NO";
else {
int half = weight / 2;
bool find = 0;
for (int i = 0; i <= two; i++)
if (200 * i <= half && half - 200 * i <= 100 * one) find = 1;
if (find)
cout << "YES";
else
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x = 0, y = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a == 100)
x++;
else if (a == 200)
y++;
}
if (x % 2 != 0 && y % 2 != 0)
cout << "NO";
else if (x % 2 != 0 && y % 2 == 0)
cout << "NO";
else if (x % 2 == 0 && y % 2 != 0 && x != 0)
cout << "YES";
else if (x % 2 == 0 && y % 2 == 0)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt[205];
int main() {
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
cnt[x]++;
}
int h = cnt[100];
int t = cnt[200];
for (int i = 0; i <= h; ++i) {
for (int j = 0; j <= t; ++j) {
int a = h - i;
int b = t - j;
if (i + 2 * j == a + 2 * b) {
printf("YES\n");
return 0;
}
}
}
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, a[101] = {0}, b[2] = {0}, i, j, k, c = 0, s = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] == 100) {
b[0]++;
} else if (a[i] == 200) {
b[1]++;
}
}
s = b[0] * 100 + b[1] * 200;
if ((s / 100) % 2 == 1) {
printf("NO\n");
} else {
if (b[0] % 2 == 1) {
printf("NO\n");
} else if (b[0] == 0) {
if (b[1] % 2 == 0) {
printf("YES\n");
} else {
printf("NO\n");
}
} else {
printf("YES\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s = 0, c = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
if (a[i] == 200) c++;
}
s = s / 100;
if (n == c && n % 2 != 0)
cout << "NO";
else if (s % 2 == 0)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int s1 = 0, s2 = 0;
for (int i = 0; i < n; i++) {
if (v[i] == 100)
s1++;
else
s2++;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
for (int m = 0; m < n; m++) {
if (i + j + k + m == n && i + k == s1 && j + m == s2) {
int a = j - m;
int b = k - i;
if (200 * a == 100 * b) {
cout << "YES" << '\n';
return 0;
}
}
}
}
}
}
cout << "NO" << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, x, y, z, s, a[1234];
int main() {
cin >> n;
if (n == 1)
cout << "NO";
else {
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 200) z++;
s += a[i];
}
if (s % 200 == 0 && (z != n || n % 2 != 1))
cout << "YES";
else
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:102400000,102400000")
using namespace std;
int f_abs(int x) { return x < 0 ? -x : x; }
int lowbit(int x) { return (x & -x); }
int f_max(int a, int b) { return a > b ? a : b; }
int f_min(int a, int b) { return a < b ? a : b; }
int gcd(int a, int b) {
while (int t = a % b) a = b, b = t;
return b;
}
bool isdig(char ch) { return ch >= '0' && ch <= '9'; }
bool isup(char ch) { return ch >= 'A' && ch <= 'Z'; }
bool islow(char ch) { return ch >= 'a' && ch <= 'z'; }
void swap(int& a, int& b) {
int t = a;
a = b;
b = t;
}
const int inf = 0x7fffffff;
const int mod = 1000000007;
const int N = 20003;
int n, a, b, sum, dp[N];
void init() {
a = b = sum = 0;
memset(dp, 0, sizeof(dp));
}
void get_data() {
int t;
for (int i = 0; i < n; ++i) {
scanf("%d", &t);
if (t == 100) {
a++;
sum++;
} else {
b++;
sum += 2;
}
}
}
void solve() {
int i, j;
dp[0] = 1;
for (i = 0; i < a; ++i) {
for (j = 0; j < N - 1; ++j) {
if (dp[j]) dp[j + 1] = 1;
}
}
for (i = 0; i < b; ++i) {
for (j = 0; j < N - 2; ++j) {
if (dp[j]) dp[j + 2] = 1;
}
}
if (sum % 2 == 0 && dp[sum / 2])
puts("YES");
else
puts("NO");
}
int main() {
while (~scanf("%d", &n)) {
init();
get_data();
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long i, j;
long long temp;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long a[n];
long long h = 0, t = 0;
for (i = 0; i < n; i++) {
cin >> temp;
if (temp == 100)
h++;
else
t++;
}
if (t % 2 == 0 && h % 2 == 0)
cout << "YES";
else if (t % 2 == 1 && h % 2 == 0 && h > 0)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int c1, c2;
int main() {
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
if (x == 100)
c1++;
else
c2++;
}
int p = c1 + c2 * 2;
if (p % 2 == 0) {
for (int i = 0; i <= c1; i++) {
for (int j = 0; j <= c2; j++) {
if (2 * i + 4 * j == p) {
puts("YES");
return 0;
}
}
}
}
puts("NO");
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 205;
int a[MAX];
bool dp[MAX];
int main() {
int n;
scanf("%d", &n);
int odd = 0;
int sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
a[i] /= 100;
sum += a[i];
}
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 200; j >= 1; --j) {
if (dp[j - a[i]]) dp[j] = 1;
}
}
if (sum % 2 || !dp[sum / 2])
printf("NO\n");
else
printf("YES\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int i, j, x, n, cnt = 0, m, y, k, g, flg;
int cn1, cn2;
cn1 = cn2 = 0;
cin >> n;
int in[n + 1];
for (i = 1; i <= n; i++) {
cin >> in[i];
if (in[i] == 100)
cn1++;
else
cn2++;
}
if (cn1 % 2 == 0 && cn1 != 0)
cout << "YES";
else if (cn1 % 2 == 0 && cn2 % 2 == 0)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
int n;
string s;
while (cin >> n) {
int flag = false;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int y = sum / 2;
int sum2;
sort(a, a + n);
for (int i = 0; i < n - 1; i++) {
sum2 = 0;
for (int j = i; j < n; j++) {
sum2 += a[j];
if (sum2 < y) continue;
if (sum2 == y) {
flag = true;
break;
}
if (sum2 > y) break;
}
if (flag) break;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; ++i) cin >> vec[i];
int sum = accumulate(vec.begin(), vec.end(), 0);
if ((sum / 100) % 2 != 0) {
cout << "NO\n";
return 0;
}
sum /= 2;
int num_one = count(vec.begin(), vec.end(), 100);
int num_two = count(vec.begin(), vec.end(), 200);
int curr = 0;
while (curr <= sum && num_two > 0) {
curr += 200;
num_two--;
}
if (curr == sum) {
cout << "YES\n";
return 0;
}
if (curr > sum) curr -= 200;
while (curr != sum && num_one > 0) {
curr += 100;
num_one--;
}
if (curr == sum)
cout << "YES\n";
else
cout << "NO\n";
}
|
#include <bits/stdc++.h>
using namespace std;
void striker() {
long long n;
cin >> n;
long long a1 = 0, a2 = 0;
long long arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n, greater<long long>());
for (long long i = 0; i < n; i++) {
if (a1 <= a2)
a1 += arr[i];
else
a2 += arr[i];
}
cout << (a1 == a2 ? "YES" : "NO");
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long t = 1;
for (long long i = 0; i < t; i++) {
striker();
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1];
int sum = 0;
int hun = 0;
int twos = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 100) {
hun++;
} else {
twos++;
}
sum += a[i];
}
if ((sum / 2) % 100 != 0) {
cout << "NO" << endl;
return 0;
}
if (hun % 2 == 0 && hun != 0) {
cout << "YES" << endl;
} else if (hun == 0 && twos % 2 == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num, w1 = 0, w2 = 0, wt;
cin >> num;
for (int a1 = 1; a1 <= num; a1++) {
cin >> wt;
if (wt == 100) {
w1++;
} else {
w2++;
}
}
if ((w2 % 2 == 1) && (w1 == 0)) {
cout << "NO";
} else if ((w2 % 2 == 0) && (w1 % 2 == 0)) {
cout << "YES";
} else if ((w2 % 2 == 1) && (w1 % 2 == 0)) {
cout << "YES";
} else if ((w2 % 2 == 1) && (w1 % 2 == 1)) {
cout << "NO";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << "NO" << endl;
return 0;
}
int w[n];
int count1 = 0, count2 = 0;
for (int i = 0; i < n; i++) {
cin >> w[i];
if (w[i] == 100)
count1++;
else
count2++;
}
if (count1 == 0 && count2 % 2 == 1) {
cout << "NO";
} else if ((count1 + 2 * count2) % 2 == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[200], num = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 100) num++;
}
int x = num * 50 + (n - num) * 100;
if (x % 100 != 0 || n == 1)
cout << "NO" << endl;
else {
if (x % 200 == 0)
cout << "YES" << endl;
else {
if (num > 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, w, one = 0, two = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &w);
(w == 100 ? one : two)++;
}
if (!(one & 1) && (!(two & 1) || (two & 1 && one)))
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int w;
int s = 0;
int s1 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w;
if (w == 100)
s++;
else
s1++;
}
if (n == 1) {
cout << "NO" << endl;
return 0;
}
if (s % 2 != 0 || s1 % 2 != 0 && s == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int cnt1 = 0, cnt2 = 0;
int x, sum = 0, ans = 0;
int i;
;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x == 100) {
cnt1++;
} else {
cnt2++;
}
}
if (cnt2 == 0) {
if (cnt1 % 2 != 0) {
cout << "NO";
} else {
cout << "YES";
}
}
if (cnt1 == 0) {
if (cnt2 % 2 == 0) {
cout << "YES";
} else {
cout << "NO";
}
}
if (cnt1 != 0 && cnt2 != 0) {
if (cnt1 % 2 != 0 && cnt2 % 2 != 0) {
cout << "NO";
}
if (cnt1 % 2 != 0 && cnt2 % 2 == 0) {
cout << "NO";
}
if (cnt1 % 2 == 0 && cnt2 % 2 != 0) {
cout << "YES";
}
if (cnt1 % 2 == 0 && cnt2 % 2 == 0) {
cout << "YES";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k1 = 0, k2 = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
if (a[i] == 100) {
k1++;
} else {
k2++;
}
}
if (k1 % 2 == 0 && (k2 % 2 == 0 || k1 > 0))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int x, cnt = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 100)
cnt++;
else
cnt2++;
}
if (cnt > 0 && cnt % 2 == 0 || cnt2 > 0 && cnt2 % 2 == 0 && cnt % 2 == 0)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int power(long long int x, long long int n) {
long long int result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % 1000000007;
x = (x * x) % 1000000007;
n = n / 2;
}
return result % 1000000007;
}
bool isPrime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int a, i, s = 0, e = 0;
for (i = 0; i < n; i++) {
cin >> a;
if (a == 100)
s++;
else
e++;
}
if (s % 2 != 0)
cout << "NO";
else if (e % 2 == 0)
cout << "YES";
else if (s > 0)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100];
cin >> n;
int i, sum = 0, odd = 0, even = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
a[i] = a[i] / 100;
if (a[i] == 1)
odd++;
else
even++;
sum += a[i];
}
if (sum % 2 == 1)
cout << "NO" << endl;
else if (odd % 2 == 0 && even % 2 == 0)
cout << "YES" << endl;
else if (odd == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
};
int total = 0;
for (int i = 0; i < n; i++) {
total += a[i];
}
if (total % 200 == 0 && (200 * n != total || n % 2 == 0))
cout << "YES";
else
cout << "NO";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
int a = 0, b = 0;
for (int i = n - 1; i >= 0; i--) {
(a > b) ? b += v[i] : a += v[i];
}
(a == b) ? cout << "YES\n" : cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
scanf("%d", &n);
int val, count1 = 0, count2 = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &val);
if (val == 200)
count2++;
else
count1++;
}
if (count2 % 2 == 0 && count1 % 2 == 0)
printf("YES\n");
else if (count2 % 2 == 0 && count1 % 2 != 0)
printf("NO\n");
else if (count2 % 2 != 0) {
if (count1 < 2)
printf("NO\n");
else if (count1 == 2)
printf("YES\n");
else if (count1 > 2 && count1 % 2 == 0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, sum, f[10005], a[105];
int main() {
scanf("%d", &n);
for (register int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
sum /= 2;
for (register int i = 1; i <= n; i++)
for (register int j = sum; j >= a[i]; j--)
f[j] = max(f[j], f[j - a[i]] + a[i]);
if (f[sum] == sum)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int log(const char* format, ...) { return 0; }
const double EPS = 10e-8;
const int MAX = 1000;
const int INF = 1 << 30;
int main(int argc, char** argv) {
int n, n100 = 0, n200 = 0;
int num;
scanf("%d", &n);
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &num);
sum += num;
if (num == 100)
n100++;
else
n200++;
}
int t = sum / 2;
sum /= 2;
while (n200 > 0 && sum - 200 >= 0) {
sum -= 200;
n200--;
}
while (n100 > 0 && sum - 100 >= 0) {
sum -= 100;
n100--;
}
if (sum == 0 && (n100 * 100 + n200 * 200 == t)) {
printf("YES");
} else {
printf("NO");
}
return EXIT_SUCCESS;
}
|
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b, long long c) {
return (a > b) ? (a > c) ? a : c : (b > c) ? b : c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n];
int i, j, k;
int actr = 0, bctr = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100)
actr++;
else
bctr++;
}
int z = actr + 2 * bctr;
if (z % 2 != 0)
cout << "NO\n";
else {
if (actr == 0) {
if (bctr % 2 != 0)
cout << "NO\n";
else
cout << "YES\n";
} else if (bctr == 0) {
if (actr % 2 == 0)
cout << "YES\n";
else
cout << "NO\n";
} else {
cout << "YES\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
void solve() {
int n, temp, n200 = 0, n100 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
if (temp == 200)
n200++;
else
n100++;
}
if (n200 % 2 == 0) {
if (n100 % 2 == 0)
cout << "YES";
else
cout << "NO";
} else {
if (n100 >= 2 && n100 % 2 == 0)
cout << "YES";
else
cout << "NO";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC = 1, t = 0;
while (t++ < TC) {
solve();
cout << "\n";
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i = i + 2)
if (n % i == 0) return false;
return true;
}
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
long long g = gcd(a, b);
long long ans = (a * b) / g;
return ans;
}
bool palindrome(string s) {
for (long long i = 0; i < s.length() / 2; i++) {
if (s[i] != s[s.length() - i - 1]) return 0;
}
return 1;
}
void printDivisors(int n) {
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i)
printf("%d ", i);
else
printf("%d %d ", i, n / i);
}
}
}
vector<long long> prime;
void primes(long long m) {
bool isprime[m];
for (int i = 0; i <= m; i++) isprime[i] = true;
for (int i = 3; i * i <= m; i++) {
if (isprime[i]) {
for (int j = i * i; j <= m; j += i) isprime[j] = false;
}
}
prime.push_back(2);
for (int i = 3; i <= m; i += 2)
if (isprime[i]) prime.push_back(i);
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int sum = 0;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
}
sort(v.rbegin(), v.rend());
for (int i = 0; i < n; i++) {
int take = 0;
for (int j = i; j < n; j++) {
if (take + v[j] <= sum / 2) take += v[j];
if (take == sum / 2 && sum - take == sum / 2) {
cout << "YES";
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double INF = 0x7ffffff;
const int N = 250;
int n, a[N];
int main() {
ios::sync_with_stdio(false);
while (scanf("%d", &n) != EOF) {
int tot = 0;
int t1 = 0, t2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
tot += a[i] / 100;
if (a[i] == 100)
t1++;
else
t2++;
}
if (tot % 2 || (t2 % 2 && t1 == 0))
puts("NO");
else {
puts("YES");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w, countl = 0, countr = 0;
cin >> n;
for (n; n > 0; n--) {
cin >> w;
if (w == 100)
countl++;
else
countr++;
}
if ((countl == 0 && countr % 2 != 0) || (countr == 0 && countl % 2 != 0))
cout << "NO";
else if (countl % 2 == 0 && countr % 2 == 0)
cout << "YES";
else {
countr %= 2;
countl %= 2;
if (countr != 0 && countl == 0)
cout << "YES";
else
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, temp;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
if (temp == 100)
b++;
else
a++;
}
if (b % 2 == 1 || (a % 2 == 1 && b < 2))
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int q(0), w(0), n, h(0), d;
cin >> n;
int a[n - 1];
if (n == 1) {
cout << "NO";
return 0;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
h += a[i];
}
h = h / 100;
if (h % 2 != 0) {
cout << "NO";
return 0;
}
h = h / 2;
d = h;
for (int i = 0; i < n; i++) {
if (a[i] == 200) {
q += 2;
} else {
w++;
}
}
for (int i = 0; i < 100; i++) {
if (h - 2 >= 0 && q > 0) {
h -= 2;
q -= 2;
} else if (h - 1 >= 0 && w > 0) {
h -= 1;
w -= 1;
} else {
cout << "NO";
return 0;
}
if (h == 0) {
if (q + w == d) {
cout << "YES";
return 0;
} else {
cout << "NO";
return 0;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
long long c1 = 0, c2 = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100) {
c1++;
} else {
c2++;
}
}
if (c1 > 0) {
if (c1 % 2 == 0) {
cout << "YES";
} else {
cout << "NO";
}
} else {
if (c2 % 2 == 0) {
cout << "YES";
} else {
cout << "NO";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie();
long long int n;
cin >> n;
long long int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long int H[2] = {0};
for (int i = 0; i < n; i++)
if (arr[i] == 100)
H[0]++;
else
H[1]++;
if ((H[0] == 0 && H[1] % 2 == 0) || (H[1] == 0 && H[0] % 2 == 0))
cout << "YES";
else if (H[0] % 2 == 0 && H[1] % 2 == 0)
cout << "YES";
else if (H[1] % 2 != 0 && H[0] % 2 == 0 && H[0] > 1)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void inout() {}
unsigned long long int mmi(unsigned long long int x) {
unsigned long long int result = 1, e = 1000000007 - 2;
while (e) {
if (e & 1) result = (result * x) % 1000000007;
x = (x * x) % 1000000007;
e >>= 1;
}
return result;
}
unsigned long long int fmod(int a) {
unsigned long long int f = 1;
for (long long i = 2; i < a + 1; i++) {
f = (f * i) % 1000000007;
}
return f;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
inout();
long long n;
cin >> n;
long long sum = 0;
long long c2 = 0;
for (long long i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 200) {
++c2;
}
sum += x;
}
if (c2 == n && c2 % 2 != 0) {
cout << "NO";
return 0;
}
if (c2 == 0 && sum % 200 == 0) {
cout << "YES";
} else if (sum % 200 == 0)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[105];
while (cin >> n) {
int u = 0;
int e = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100) {
u++;
}
}
if (u % 2 == 1 || (n % 2 == 1 && u == 0)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b = 0, n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 100)
a++;
else {
b++;
}
}
if (a % 2 != 0 || (b % 2 != 0 && a <= 1)) {
printf("NO\n");
} else {
printf("YES\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
int n, s, k = 0, l = 0, j, tot;
cin >> n;
j = n;
while (n--) {
cin >> s;
s == 200 ? k++ : l++;
}
tot = k * 2 + l;
if (tot & 1 || l & 1 || (!l && k & 1) || j == 1) {
cout << "NO\n";
} else
cout << "YES\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int main(void) {
int n, tw, h;
cin >> n;
for (i = 0; i < n; i++) {
cin >> j;
if (j == 100)
h++;
else
tw++;
}
if (h == 0 && (tw % 2 != 0)) {
cout << "NO";
return 0;
}
if ((h + (2 * tw)) % 2 != 0) {
cout << "NO";
} else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a = 0, b = 0;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 200)
a++;
else
b++;
}
if (b % 2 || a % 2 && b == 0)
cout << "NO";
else
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, p, w, h = 0;
cin >> n;
p = n;
while (n--) {
cin >> w;
if (w == 100) h++;
}
if (h % 2 != 0) {
cout << "NO";
} else if (p % 2 != 0 && h == 0) {
cout << "NO";
} else {
cout << "YES";
}
cout << "\n";
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c1 = 0, c2 = 0, a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (a == 100)
c1++;
else
c2++;
}
if ((c2 * 2 + c1) % 2 != 0)
cout << "NO\n";
else {
if (c2 % 2 == 0) {
cout << "YES\n";
} else {
if (c1 < 2) {
cout << "NO\n";
} else
cout << "YES\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(INT_MAX - 100);
const int N = (int)(0);
const long long mod = (int)(1e+9 + 7);
int main() {
int n, p;
cin >> n;
vector<int> C(3);
for (int it1 = 0; it1 < n; it1++) {
scanf("%d", &p);
C[p / 100]++;
}
if (C[1] & 1) return puts("NO"), 0;
if (C[1] == 0 && (C[2] & 1))
puts("NO");
else
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
int a;
cin >> n;
int k = 0, t = 0, count = 0;
while (n--) {
cin >> a;
if (a == 100) k++;
if (a == 200) t++;
}
if (k % 2 == 1)
count++;
else {
if (t % 2 == 1) {
if (k == 0) count++;
}
}
if (count == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, d, t = 0, o = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> d;
if (d == 200)
t++;
else
o++;
}
if (o % 2 == 0 && o > 0)
cout << "YES";
else if (o == 0 && t % 2 == 0)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h1 = 0, h2 = 0, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 100)
h1++;
else
h2++;
}
if ((h1 + 2 * h2) % 2 != 0) {
cout << "NO";
return 0;
}
if (n % 2 == 0 && h1 % 2 != h2 % 2) {
cout << "NO";
return 0;
}
if (h1 == 0 && h2 % 2 != 0) {
cout << "NO";
return 0;
}
if (h2 == 0 && h1 % 2 != 0) {
cout << "NO";
return 0;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 505;
int n, sum, a, b, x;
bool ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 100)
a++;
else
b++;
}
sum = 100 * a + 200 * b;
if (sum % 200 != 0) {
cout << "NO";
return 0;
}
sum /= 2;
for (int i = 0; i <= b; i++) {
if (i * 200 <= sum && sum - 200 * i <= 100 * a) ans = true;
}
if (ans)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << "NO";
return 0;
}
int cien = 0, doscien = 0;
int contador = 0;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (temp == 100)
cien++;
else
doscien++;
contador += temp;
}
if (contador % 200 == 0) {
if (doscien % 2 != 0 && cien == 0)
cout << "NO";
else
cout << "YES";
} else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int nc = 0;
int nd = 0;
for (int i = 0; i < t; i++) {
int w;
cin >> w;
if (w == 100) {
nc++;
} else {
nd++;
}
}
if ((nc % 2 == 0 && nd % 2 == 0) || (nc % 2 == 0 && nd % 2 != 0 && nc != 0)) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, b, c, s[11000001], i;
int main() {
cin >> a;
for (i = 1; i <= a; i++) {
cin >> s[i];
if (s[i] == 100) {
b++;
} else {
c += 2;
}
}
if (a == 1) {
cout << "NO";
return 0;
}
if (b == 0 && a % 2 == 1) {
cout << "NO";
return 0;
}
if (b == 0 && a % 2 == 0) {
cout << "YES";
return 0;
}
if (c == 0 && a % 2 == 0) {
cout << "YES";
return 0;
}
if (c == 0 && a % 2 == 1) {
cout << "NO";
return 0;
}
if (b % 2 == 1) {
cout << "NO";
return 0;
}
if (b % 2 == 0) {
cout << "YES";
return 0;
}
if (abs(b - c) % 2 == 0) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void yala_bena() {
cin.tie(0);
std::ios::sync_with_stdio(0);
}
const int m_r = 999999;
int main() {
yala_bena();
int n, a, h1 = 0, h2 = 0;
long long sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (a == 100)
h1++;
else
h2++;
sum += a;
}
if (h1 == 0 && h2) {
if (h2 % 2) {
cout << "NO" << endl;
return 0;
} else {
cout << "YES" << endl;
return 0;
}
} else if (h2 == 0 && h1) {
if (h1 % 2) {
cout << "NO" << endl;
return 0;
} else {
cout << "YES" << endl;
return 0;
}
} else if (h1 == h2) {
if (h1 % 2 == 0 && h2 % 2 == 0) {
cout << "YES" << endl;
return 0;
} else {
cout << "NO" << endl;
return 0;
}
} else if (h1 < h2) {
if (h1 % 2 == 0 && h2 % 2 == 0) {
cout << "YES" << endl;
return 0;
} else if (h2 & 2 == 0 && h1 % 2 == 1) {
cout << "NO" << endl;
return 0;
} else if (h2 % 2 == 1 && h1 % 2 == 0) {
cout << "YES" << endl;
return 0;
}
} else if (h2 < h1) {
if (h1 % 2 == 0 && h2 % 2 == 0) {
cout << "YES" << endl;
return 0;
} else if (h2 & 2 == 0 && h1 % 2 == 1) {
cout << "NO" << endl;
return 0;
} else if (h2 % 2 == 1 && h1 % 2 == 0) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, a = 0, b = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> j;
if (j == 100)
a++;
else
b++;
}
j = (a * 100 + b * 200);
bool f1 = false;
if (j % 200 != 0) {
cout << "NO";
} else {
j /= 2;
for (i = 0; i <= b; i++) {
if (j >= 200 * i && j - 200 * i <= a * 100) f1 = true;
}
if (f1)
cout << "YES";
else
cout << "NO";
}
cout << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a = 0;
int i, w;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &w);
if (w == 100) {
a++;
}
}
if (a % 2 == 1 || (n % 2 == 1 && a == 0)) {
printf("NO\n");
} else {
printf("YES\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int n;
cin >> n;
int a[n];
int cnt = 0, cnt1 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 100)
cnt++;
else
cnt1++;
}
if (cnt & 1) {
cout << "NO\n";
return;
}
if ((cnt1 & 1) == 0) {
cout << "YES\n";
return;
}
if (cnt < 2)
cout << "NO\n";
else
cout << "YES\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, x, c1 = 0, c2 = 0;
bool flag = false;
cin >> n;
while (n--) {
cin >> x;
if (x == 100)
++c1;
else
++c2;
}
if (c1 % 2 == 0) {
if ((c1 == 0 && c2 % 2 == 0) || (c1 > 0)) flag = true;
}
if (flag) {
cout << "YES";
} else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, a[300000], b[100000] = {0}, c[100000] = {0}, x, y, xx, yy, t,
p, q, n, ll, rr, r, cap, cap2;
char l[1000], lll[1000], bb[200000], tt[1000];
int main() {
cin >> x;
p = 0;
q = 0;
y = 0;
for (i = 0; i < x; i++) {
cin >> a[i];
y = y + a[i];
if (a[i] == 100)
p++;
else
q++;
}
if (p % 2 != 0) {
cout << "NO\n";
return 0;
} else if (p == 0) {
if (q % 2 == 0)
cout << "YES\n";
else
cout << "NO\n";
} else
cout << "YES\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num, suma1 = 0, suma2 = 0, cont1 = 0, cont2 = 0, aux;
cin >> num;
for (int i = 0; i < num; i++) {
cin >> aux;
if (aux == 100) {
suma1 += 100;
cont1++;
} else {
suma2 += 200;
cont2++;
}
}
if (num == 1) {
cout << "NO";
return 0;
}
if (cont1 % 2 != 0) {
cout << "NO";
return 0;
}
if (cont2 == 0) {
cout << "YES";
return 0;
}
if (cont2 % 2 != 0 && cont1 != 0) {
cout << "YES";
return 0;
} else if (cont2 % 2 != 0 && cont1 == 0) {
cout << "NO";
return 0;
}
if (cont2 % 2 == 0) {
cout << "YES";
return 0;
}
}
|
#include <bits/stdc++.h>
int main() {
int n, w, cnt1, cnt2;
scanf("%d", &n);
cnt1 = cnt2 = 0;
while (n-- > 0) {
scanf("%d", &w);
if (w == 100)
cnt1++;
else
cnt2++;
}
printf("%s\n", cnt1 % 2 == 0 && (cnt2 % 2 == 0 || cnt1 >= 2) ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int main(void) {
int n, tw, h;
cin >> n;
for (i = 0; i < n; i++) {
cin >> j;
if (j == 100)
h++;
else
tw++;
}
if (h == 0 && tw % 2 != 0) {
cout << "NO";
return 0;
}
if ((h + (2 * tw)) % 2 != 0) {
cout << "NO";
} else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a = 0, b = 0, x;
cin >> n;
while (n--) {
cin >> x;
((x == 100) ? ++a : ++b);
}
if (a & 1)
cout << "NO";
else {
cout << (((a % 2 == 0 && b % 2 == 0) || ((a % 2 == 0 && a > 0) && b & 1))
? "YES"
: "NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int n, m;
int f[maxn];
int diameter[maxn];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
vector<int> G[maxn];
int d1[maxn], d2[maxn];
int vis[maxn], t;
queue<int> q;
int bfs1(int u, int d[]) {
t++;
q.push(u);
d[u] = 0;
vis[u] = t;
while (!q.empty()) {
u = q.front();
q.pop();
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (vis[v] == t) continue;
q.push(v);
d[v] = d[u] + 1;
vis[v] = t;
}
}
return u;
}
int bfs2(int u, int fa, int tag) {
int ret = -1;
t++;
q.push(u);
d2[u] = 0;
vis[u] = t;
while (!q.empty()) {
u = q.front();
q.pop();
f[u] = fa;
if (d1[u] + d2[u] == tag) {
if (d1[u] == tag / 2 || d2[u] == tag / 2) ret = u;
}
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (vis[v] == t) continue;
q.push(v);
d2[v] = d2[u] + 1;
vis[v] = t;
}
}
return ret;
}
void bfs3(int u) {
int fa = u;
t++;
q.push(u);
vis[u] = t;
while (!q.empty()) {
u = q.front();
q.pop();
f[u] = fa;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (vis[v] == t) continue;
q.push(v);
vis[v] = t;
}
}
}
int main() {
int Q;
scanf("%d%d%d", &n, &m, &Q);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 0; i < n; i++)
if (!vis[i]) {
int x = bfs1(i, d1);
int y = bfs1(x, d1);
int z = bfs2(y, y, d1[y]);
diameter[z] = d1[z] + d2[z];
bfs3(z);
}
for (int i = 0; i < Q; i++) {
int op;
scanf("%d", &op);
if (op == 1) {
int x;
scanf("%d", &x);
x--;
x = find(x);
printf("%d\n", diameter[x]);
} else {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
x = find(x), y = find(y);
if (x != y) {
if (diameter[x] > diameter[y]) {
int t1 = diameter[x] / 2, t2 = diameter[x] - t1;
int t3 = diameter[y] / 2, t4 = diameter[y] - t3;
f[y] = x;
diameter[x] = max(max(diameter[x], diameter[y]), t2 + t4 + 1);
} else {
int t1 = diameter[x] / 2, t2 = diameter[x] - t1;
int t3 = diameter[y] / 2, t4 = diameter[y] - t3;
f[x] = y;
diameter[y] = max(max(diameter[x], diameter[y]), t2 + t4 + 1);
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 10;
int n, m, q;
vector<int> g[N];
int parent[N], rang[N], diametr[N];
bool used[N];
pair<int, int> mx;
void dfs(int v, int prev = -1, int h = 0) {
mx = max(mx, make_pair(h, v));
for (int i = 0; i < g[v].size(); ++i) {
int to = g[v][i];
if (to == prev) continue;
dfs(to, v, h + 1);
}
}
int get_tree_diametr(int v) {
mx = make_pair(-1, -1);
dfs(v);
v = mx.second;
mx = make_pair(-1, -1);
dfs(v);
return mx.first;
}
void make_set(int v) {
parent[v] = v;
rang[v] = 0;
diametr[v] = 0;
}
int find_set(int v) {
if (parent[v] == v) return v;
return parent[v] = find_set(parent[v]);
}
void union_set1(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (rang[a] < rang[b]) swap(a, b);
parent[b] = a;
if (rang[a] == rang[b]) rang[a]++;
}
}
void union_set2(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (rang[a] < rang[b]) swap(a, b);
parent[b] = a;
if (rang[a] == rang[b]) rang[a]++;
diametr[a] = max(diametr[a],
max(diametr[b], diametr[a] / 2 + diametr[b] / 2 +
diametr[a] % 2 + diametr[b] % 2 + 1));
}
}
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 0; i < n; ++i) make_set(i);
for (int i = 0; i < m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
union_set1(x, y);
}
for (int i = 0; i < n; ++i) {
int s = find_set(i);
if (used[s]) continue;
used[s] = true;
diametr[s] = get_tree_diametr(i);
}
while (q--) {
int tp;
scanf("%d", &tp);
switch (tp) {
case 1: {
int x;
scanf("%d", &x);
x--;
printf("%d\n", diametr[find_set(x)]);
break;
}
case 2: {
int x, y;
scanf("%d%d", &x, &y);
x--;
y--;
union_set2(x, y);
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long M = 3e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
int mit[M], dmit[M], pr[M], reg[M];
vector<int> adj[M];
int find(int u) {
if (pr[u] == u) return u;
return pr[u] = find(pr[u]);
}
void jnt(int u, int v) {
int a = find(u), b = find(v);
if (a == b) return;
pr[a] = b;
}
void dfs(int u, int p) {
int mx = 0, smx = 0;
for (auto v : adj[u]) {
if (v == p) continue;
dfs(v, u);
if (mit[v] >= mx) {
smx = mx;
mx = mit[v];
} else
smx = max(smx, mit[v]);
dmit[u] = max(dmit[u], dmit[v]);
}
mit[u] = mx + 1;
dmit[u] = max(dmit[u], mx + smx + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) pr[i] = i;
for (int i = 0, u, v; i < m; i++) {
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
jnt(u, v);
}
for (int i = 1; i <= n; i++) {
int p = find(i);
if (reg[p] == 0) {
dfs(p, 0);
reg[p] = dmit[p];
}
}
for (int i = 1; i <= n; i++) {
int p = find(i);
}
while (q--) {
int tp, x, y, p, p1, p2;
cin >> tp;
if (tp == 1) {
cin >> x;
p = find(x);
cout << reg[p] - 1 << endl;
}
if (tp == 2) {
cin >> x >> y;
p1 = find(x);
p2 = find(y);
if (p1 == p2) continue;
jnt(x, y);
p = find(x);
reg[p] = max(max(reg[p1], reg[p2]), reg[p1] / 2 + 2 + reg[p2] / 2);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct disjoint_set {
int *parent;
int *rank;
int components;
disjoint_set(int n) {
parent = new int[n];
rank = new int[n];
components = n;
for (int i = 0; i < n; i++) {
parent[i] = i;
rank[i] = 0;
}
}
int find(int s) { return parent[s] == s ? s : find(parent[s]); }
bool equal(int s1, int s2) { return find(s1) == find(s2); }
void join(int s1, int s2) {
int p1 = find(s1);
int p2 = find(s2);
if (p1 == p2) return;
if (rank[p1] == rank[p2]) ++rank[p1];
if (rank[p1] < rank[p2]) swap(p1, p2);
parent[p2] = p1;
--components;
}
};
int n, m;
disjoint_set ds(300005);
vector<int> adj[300005];
bool vis[300005];
int dist[300005];
int arr[300005];
int per[300005];
int getPrim(int st) {
queue<int> q;
q.push(st);
int lstNode = st;
while (!q.empty()) {
int v = q.front();
vis[v] = 1;
q.pop();
lstNode = v;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i];
if (!vis[u]) {
ds.join(st, u);
q.push(u);
}
}
}
dist[lstNode] = 0;
per[lstNode] = -1;
q.push(lstNode);
while (!q.empty()) {
int v = q.front();
q.pop();
lstNode = v;
for (int i = 0; i < adj[v].size(); i++) {
int u = adj[v][i];
if (per[v] != u) {
per[u] = v;
dist[u] = dist[v] + 1;
q.push(u);
}
}
}
return dist[lstNode];
}
int main() {
memset(dist, 0, sizeof dist);
memset(arr, 0, sizeof arr);
int q, a, b;
cin >> n >> m >> q;
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
a--;
b--;
adj[b].push_back(a);
adj[a].push_back(b);
}
for (int i = 0; i < n; i++)
if (!vis[i]) {
int num = getPrim(i);
arr[ds.find(i)] = num;
}
for (int i = 0; i < q; i++) {
scanf("%d%d", &a, &b);
b--;
if (a == 1)
printf("%d\n", arr[ds.find(b)]);
else {
scanf("%d", &a);
a--;
if (!ds.equal(a, b)) {
int d1 = arr[ds.find(a)];
int d2 = arr[ds.find(b)];
int mx = max(d1, d2);
d1++;
d2++;
ds.join(a, b);
arr[ds.find(a)] = max(d1 / 2 + d2 / 2 + 1, mx);
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 100007;
int par[N], _rank[N], mx, mx_v, diameter[N], used[N];
vector<int> adj[N];
void dfs(int v, int d, int p) {
if (mx < d) {
mx = d;
mx_v = v;
}
for (auto x : adj[v])
if (x != p) dfs(x, d + 1, v);
}
int cal_dia(int v) {
mx = -1;
dfs(v, 0, -1);
mx = -1;
dfs(mx_v, 0, -1);
return mx;
}
int find_set(int x) {
if (par[x] == x) return x;
return par[x] = find_set(par[x]);
}
void _union(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (_rank[a] < _rank[b]) swap(a, b);
par[b] = a;
if (_rank[a] == _rank[b]) ++_rank[a];
}
}
int rad(int val) { return (diameter[val] + 1) / 2; }
void __union(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (_rank[a] < _rank[b]) swap(a, b);
par[b] = a;
if (_rank[a] == _rank[b]) ++_rank[a];
diameter[a] = max(rad(a) + rad(b) + 1, max(diameter[a], diameter[b]));
}
}
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; ++i) par[i] = i;
while (m--) {
int a, b;
scanf("%d%d", &a, &b);
adj[a].push_back(b);
adj[b].push_back(a);
_union(a, b);
}
for (int i = 1; i <= n; ++i) {
int pp = find_set(i);
if (!used[pp]) {
used[pp] = 1;
diameter[pp] = cal_dia(i);
}
}
while (q--) {
int a, b, c;
scanf("%d%d", &c, &a);
if (c == 1)
printf("%d\n", diameter[find_set(a)]);
else {
scanf("%d", &b);
__union(a, b);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct edge {
int x, y;
friend bool operator<(const edge& a, const edge& b);
};
edge a[600010];
int m, n, q, x, y, t;
int f[300010][2];
int fa[300010];
int ans[300010];
int start[300010], finish[300010];
bool operator<(const edge& a, const edge& b) { return a.x < b.x; }
int find(int x) {
if (x == fa[x])
return x;
else {
fa[x] = find(fa[x]);
return fa[x];
}
}
void search(int k, int pre) {
f[k][0] = 0;
f[k][1] = 0;
int max1 = -1, max2 = -1;
for (int i = start[k]; i < finish[k]; i++) {
if (a[i].y != pre) {
search(a[i].y, k);
f[k][0] = max(f[k][0], f[a[i].y][0]);
f[k][1] = max(f[k][1], f[a[i].y][1] + 1);
int tmp = f[a[i].y][1];
if (tmp >= max1) {
max2 = max1;
max1 = tmp;
} else if (tmp > max2) {
max2 = tmp;
}
}
}
f[k][0] = max(f[k][0], max1 + max2 + 2);
}
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++) fa[i] = i;
for (int i = 0; i < m; i++) {
scanf("%d%d", &a[i * 2].x, &a[i * 2].y);
a[i * 2 + 1].x = a[i * 2].y;
a[i * 2 + 1].y = a[i * 2].x;
fa[find(a[i * 2].y)] = find(a[i * 2].x);
}
m *= 2;
sort(a, a + m);
start[a[0].x] = 0;
if (m > 0) finish[a[m - 1].x] = m;
for (int i = 1; i < m; i++) {
if (a[i].x != a[i - 1].x) {
finish[a[i - 1].x] = i;
start[a[i].x] = i;
}
}
for (int i = 1; i <= n; i++) {
if (fa[i] == i) {
search(i, 0);
}
ans[i] = f[i][0];
}
for (int i = 0; i < q; i++) {
scanf("%d", &t);
if (t == 1) {
scanf("%d", &x);
printf("%d\n", ans[find(x)]);
} else {
scanf("%d%d", &x, &y);
if (find(x) != find(y)) {
ans[find(x)] = max((ans[find(x)] + 1) / 2 + (ans[find(y)] + 1) / 2 + 1,
ans[find(x)]);
ans[find(x)] = max(ans[find(x)], ans[find(y)]);
fa[find(y)] = find(x);
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
template <class T>
inline void in(T &x) {
x = 0;
register char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + c - 48, c = getchar();
}
int dot, line, q, cnt, root, pos;
int head[300050], dia[300050], bel[300050], dep[300050];
bool vis[300050];
struct Edge {
int to, nex;
} edge[300050 << 1];
inline void addedge(const int &from, const int &to) {
edge[++cnt] = {to, head[from]}, head[from] = cnt;
}
namespace DSU {
int find(const int &now) {
return bel[now] == now ? now : bel[now] = find(bel[now]);
}
inline void combine(register int x, register int y) { bel[x] = find(y); }
} // namespace DSU
void DFS(const int &now, const int &fa) {
vis[now] = true;
if (dep[now] > dep[pos]) pos = now;
for (register int i = head[now]; i; i = edge[i].nex) {
if (edge[i].to == fa) continue;
dep[edge[i].to] = dep[now] + 1;
DFS(edge[i].to, now);
}
}
void merge(const int &now, const int &tar, const int &fa) {
bel[now] = tar;
for (register int i = head[now]; i; i = edge[i].nex) {
if (edge[i].to == fa) continue;
merge(edge[i].to, tar, now);
}
}
void prework(const int &now) {
pos = now;
DFS(now, 0);
root = pos;
dep[root] = 0;
DFS(root, 0);
dia[root] = dep[pos];
merge(root, root, 0);
}
int main(void) {
int a, b, typ;
in(dot), in(line), in(q);
for (register int i = 1; i <= line; ++i)
in(a), in(b), addedge(a, b), addedge(b, a);
for (register int i = 1; i <= dot; ++i)
if (!vis[i]) prework(i);
while (q--) {
in(typ);
if (typ & 1)
in(a), printf("%d\n", dia[DSU::find(a)]);
else {
in(a), in(b);
register int x = DSU::find(a), y = DSU::find(b);
if (x == y) continue;
dia[y] = std::max(std::max(dia[y], dia[x]),
(dia[y] + 1) / 2 + (dia[x] + 1) / 2 + 1);
DSU::combine(x, y);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1, 1, -1, -1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int N = 3e5 + 5;
int C[N], p[N];
int diam[N];
int n, m, q;
vector<int> adj[N];
void init() {
for (int i = 0; i < N; i++) C[i] = 0, p[i] = i;
}
inline int findp(int x) { return x == p[x] ? x : p[x] = findp(p[x]); }
void merge(int u, int v, int d = -1) {
u = findp(u);
v = findp(v);
if (u == v) return;
if (C[u] < C[v]) swap(u, v);
p[v] = u;
if (~d)
diam[u] =
max(diam[u], max(diam[v], (diam[u] + 1) / 2 + (diam[v] + 1) / 2 + 1));
if (C[u] == C[v]) C[u]++;
}
int MAXL;
int MAXNode;
int vis[N];
int visID = 1;
void dfs(int u, int level, int par = -1) {
if (level > MAXL) MAXL = level, MAXNode = u;
if (vis[u] == visID) return;
vis[u] = visID;
for (int i = 0; i < int((adj[u]).size()); i++)
if (adj[u][i] != par) dfs(adj[u][i], level + 1, u);
}
int main() {
int u, v;
init();
scanf("%d", &n), scanf("%d", &m), scanf("%d", &q);
for (int i = 0; i < m; ++i) {
scanf("%d", &u), scanf("%d", &v);
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
merge(u, v);
}
memset(diam, -1, sizeof(diam));
for (int i = 0; i < n; ++i) {
int par = findp(i);
if (diam[par] == -1) {
MAXL = 0;
dfs(i, 1);
visID++;
MAXL = 0;
dfs(MAXNode, 1);
diam[par] = MAXL - 1;
}
}
int type;
for (int i = 0; i < q; ++i) {
scanf("%d", &type), scanf("%d", &u);
if (type == 1) {
printf("%d\n", diam[findp(u - 1)]);
} else {
scanf("%d", &v);
merge(u - 1, v - 1, 1);
}
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.