Skip to content

Commit 9a827c1

Browse files
committed
Add Round #395 from CF
1 parent 066a934 commit 9a827c1

File tree

4 files changed

+154
-1
lines changed

4 files changed

+154
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// http://codeforces.com/contest/764/problem/A
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
#define endl '\n'
7+
#define D(x) cout << #x << " = " << (x) << endl;
8+
9+
int main() {
10+
int n, m, z;
11+
cin >> n >> m >> z;
12+
13+
vector<int> v(z + 1, 0);
14+
for (int i = m; i <= z; i += m) {
15+
v[i] = 1;
16+
}
17+
18+
19+
int ans = 0;
20+
for (int i = n; i <= z; i += n) {
21+
if (v[i]) ans ++;
22+
}
23+
24+
cout << ans << endl;
25+
return 0;
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// http://codeforces.com/contest/764/problem/B
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
#define endl '\n'
7+
#define D(x) cout << #x << " = " << (x) << endl;
8+
9+
int main() {
10+
int n;
11+
cin >> n;
12+
13+
vector<int> v(n);
14+
for (int i = 0; i < n; ++i) cin >> v[i];
15+
16+
int a = 0;
17+
int b = n - 1;
18+
19+
int cnt = 0;
20+
while (a <= b) {
21+
if (cnt % 2 == 0)
22+
swap(v[a], v[b]);
23+
24+
a ++;
25+
b --;
26+
cnt ++;
27+
}
28+
29+
for (int i = 0; i < n; ++i) cout << v[i] << " "; cout << endl;
30+
31+
return 0;
32+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// http://codeforces.com/contest/764/problem/C
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
#define endl '\n'
7+
#define D(x) cout << #x << " = " << (x) << endl;
8+
9+
vector<int> G[110000];
10+
vector<int> color(110000, 0);
11+
vector<int> visited(110000, 0);
12+
13+
bool check (int i, int root) {
14+
queue<int> Q;
15+
Q.push(i);
16+
17+
while (!Q.empty()) {
18+
int cur = Q.front(); Q.pop();
19+
visited[cur] = true;
20+
21+
for (int j = 0; j < G[cur].size(); ++j) {
22+
int next = G[cur][j];
23+
if (next == root) continue;
24+
if (color[next] != color[cur]) return false;
25+
if (!visited[next]) {
26+
Q.push(next);
27+
}
28+
}
29+
}
30+
31+
return true;
32+
}
33+
34+
int main() {
35+
int n;
36+
cin >> n;
37+
38+
for (int i = 0; i < n - 1; ++i) {
39+
int a, b;
40+
cin >> a >> b;
41+
42+
G[a].push_back(b);
43+
G[b].push_back(a);
44+
}
45+
46+
for (int i = 0; i < n; ++i) {
47+
int a;
48+
cin >> a;
49+
color[i + 1] = a;
50+
}
51+
52+
int mm = 0;
53+
int bestRoot = -1;
54+
55+
for (int i = 1; i <= n; ++i) {
56+
int cnt = 0;
57+
for (int j = 0; j < G[i].size(); ++j) {
58+
int child = G[i][j];
59+
if (color[child] != color[i]) {
60+
cnt ++;
61+
}
62+
}
63+
64+
if (cnt > mm) {
65+
mm = cnt;
66+
bestRoot = i;
67+
}
68+
}
69+
70+
if (bestRoot == -1) {
71+
cout << "YES" << endl;
72+
cout << 1 << endl;
73+
return 0;
74+
}
75+
76+
bool ok = true;
77+
for (int j = 0; j < G[bestRoot].size(); ++j) {
78+
int child = G[bestRoot][j];
79+
if (!check(child, bestRoot)) {
80+
ok = false;
81+
break;
82+
}
83+
}
84+
85+
if (ok) {
86+
cout << "YES" << endl;
87+
cout << bestRoot << endl;
88+
}
89+
else cout << "NO" << endl;
90+
91+
return 0;
92+
}

codeforces/data.db

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,4 +919,7 @@
919919
24355390
920920
24357000
921921
24126930
922-
24132337
922+
24132337
923+
24366846
924+
24374352
925+
24384579

0 commit comments

Comments
 (0)