output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; long long a, b, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, row = 0, col = 0; int main() { long long t; a = 0; b = 0; c = 0; d = 0; e = 0; f = 0; g = 0; h = 0; row = 0; col = 0; cin >> a; string s; if (a == 24) { cin >> s; b = s.size(); ...
### Prompt Please provide a cpp coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> void output(int ph, int pm) { if (ph < 10) printf("0%d:", ph); else printf("%d:", ph); if (pm < 10) printf("0%d\n", pm); else printf("%d\n", pm); } int main() { int n, hh, mm; int ph, pm; scanf("%d", &n); scanf("%d:%d", &hh, &mm); if (n == 12) { if (hh >= 1...
### Prompt Please create a solution in CPP to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& out, const vector<T>& v) { out << "["; for (auto vi : v) out << vi << ", "; out << "]\n"; return out; } int DX[] = {0, +1, 0, -1, 0}; int DY[] = {+1, 0, -1, 0, 0}; int format; string HHMM; int diff(string a, string ...
### Prompt Your task is to create a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. Yo...
#include <bits/stdc++.h> long long int ciel(double a) { long long int ret = a; if (a - ret > 0.0000000001) ret++; return ret; } long long int gcd(long long int a, long long int b) { if (a < b) return gcd(b, a); if (a % b == 0) return b; return gcd(b, a % b); } long long int lcm(long long int a, long long in...
### Prompt Please provide a Cpp coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; char s[10]; int n; int main() { scanf("%d%s", &n, s); char &c1 = s[0], c2 = s[1], c3 = s[3], c4 = s[4]; if (n == 24) { if (c1 > '2') { printf("0%c", c2); } if (c1 == '2') { if (c2 < '4') printf("%c%c", c1, c2); else printf...
### Prompt Please provide a cpp coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int main() { int c, a, b; scanf("%d", &c); scanf("%02d:%02d", &a, &b); if (b >= 60) b %= 10; if (a > c || a == 24) { a %= 10; } if (c == 12 && a == 0) a = 10; printf("%02d:%02d", a, b); }
### Prompt Generate a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a ...
#include <bits/stdc++.h> using namespace std; int main() { long form, hh, mm; char colon; cin >> form >> hh >> colon >> mm; if (mm >= 60) mm = 50 + (mm % 10); if (form == 12) { if (hh > 12) hh %= 10; if (hh == 0) hh = 10; } else { if (hh >= 24) hh %= 10; } cout << setfill('0') << setw(2) << ...
### Prompt Your task is to create a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. Yo...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a = (int)s[0]; int b = (int)s[1]; int c = (int)s[3]; int d = (int)s[4]; a = a - 48; b = b - 48; c = c - 48; d = d - 48; int i = 0; int f = 10 * a + b; int g = 10 * c + d; if (n == 12) { ...
### Prompt Construct a CPP code solution to the problem outlined: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are giv...
#include <bits/stdc++.h> using namespace std; int main() { char a[18]; int i, n, j; cin >> n; cin >> a; if (n > 12) { if (a[0] > '2') a[0] = '0'; if (a[1] > '3' && a[0] > '1') a[0] = '0'; if (a[3] > '5') a[3] = '0'; } else { if (a[0] > '1' && a[1] != '0') a[0] = '0'; else if (a[0] ...
### Prompt Please formulate a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int INF = 0x3f3f3f3f; const double inf = 0x3f3f3f3f3f3f; const long long LNF = 0x3f3f3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-8; const int maxn = 1e5 + 5; const long long mod = 10000000000007...
### Prompt Please formulate a cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int main() { int type, i, x, y; scanf("%d", &type); scanf("%d:%d", &x, &y); if (type == 12) { if (x > 12) { if (x % 10 != 0) x %= 10; else x = 10; } else if (x == 0) x = 1; if (y > 59) y %= 10; } else { if (x >= 24...
### Prompt Construct a cpp code solution to the problem outlined: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are giv...
#include <bits/stdc++.h> using namespace std; int main() { int t, h, m; scanf("%d", &t); scanf("%d:%d", &h, &m); if (t == 12) { if (h == 0) h = 1; else if (h > 12) { if (h % 10 == 0) h = 10; else h %= 10; } if (m > 59) m %= 10; } else { if (h > 23) h %= 10...
### Prompt Please provide a CPP coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int h, m, n; int main() { scanf("%d\n", &n); scanf("%d:%d", &h, &m); if (n == 24) { if (h <= 23) { if (h < 10) printf("0"); printf("%d:", h); } else printf("0%d:", h % 10); if (m <= 59) { if (m < 10) printf("0"); printf("%d", ...
### Prompt Generate a cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; } inline double dist(double x1, double y1, double x2, double y2) { return sqrt(((x1 - x2) * (x1 - x2)) +...
### Prompt Develop a solution in Cpp to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> int main() { int a, b, c; scanf("%d", &c); scanf("%02d:%02d", &a, &b); if (b >= 60) b %= 10; if (a > c || a == 24) a %= 10; if (c == 12 && a == 0) a = 10; printf("%02d:%02d", a, b); }
### Prompt Your challenge is to write a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; void print(int num) { if (num < 10) { printf("0%d", num); } else { printf("%d", num); } } int main() { int h; char time[6]; scanf("%d%s", &h, time); int hour = (time[0] - '0') * 10 + time[1] - '0'; int minu = (time[3] - '0') * 10 + time[4] - '0'; i...
### Prompt Develop a solution in CPP to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T b, T p, T M) { long long ret = 1; for (; p > 0; p >>= 1) { if (p & 1) ret = (ret * b) % M; b = (b * b) % M; } return (T)ret; } template <class T> inline T lcm(T a, T b) { return (a * b) / __gcd(a, b); } int dx4[] = {1, ...
### Prompt Please create a solution in CPP to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> const double PI = acos(-1.0); const double e = exp(1.0); template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } using namespace std; char str[10]; int work1(int f) { int l, r; if (f == 12) { l = 1; r ...
### Prompt Your challenge is to write a cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> int main() { int n; char c[10]; scanf("%d", &n); getchar(); if (n == 24) { gets(c); if (c[0] > '2') { c[0] = '0'; if (c[3] > '5') c[3] = '0'; } if ((c[0] == '2') && (c[1] > '3')) { c[1] = '0'; if (c[3] > '5') c[3] = '0'; } if (c[3] > '5'...
### Prompt Please create a solution in CPP to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n; string s; string func(int a, int b) { string r1 = to_string(a); string r2 = to_string(b); while (r1.size() < 2) r1 = '0' + r1; while (r2.size() < 2) r2 = '0' + r2; r1 += ':' + r2; return r1; } int solve(int a, int b) { st...
### Prompt Please provide a CPP coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int main() { int a; string s; cin >> a; cin >> s; int c = (a / 10); if ((c == 1 && s[0] > '1') || (c == 2 && s[0] > '2')) { if (s[1] == '0' && c == 1) s[0] = '1'; else s[0] = '0'; } else if ((c == 1 && s[0] == '1' && s[1] >= '3') || ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); char a[10]; scanf("%s", a); if (n == 12) { if (a[0] > '1') { if (a[1] == '0') a[0] = '1'; else a[0] = '0'; } if (a[1] > '2' && a[0] > '0') a[1] = '0'; if (a[0] == '0' && a[1] == '0') ...
### Prompt Please provide a Cpp coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> int main() { int n; while (scanf("%d", &n) == 1) { int s, g; scanf("%d:%d", &s, &g); if (n == 12) { if (s == 0) { s = 1; } if (s > 12) { s = s % 10; if (s == 0) s = 10; } } else { if (s > 23) { s = s % 10; }...
### Prompt Generate a Cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a ...
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int dx2[] = {1, -1, -1, 1, 0, 0, -1, 1}; int dy2[] = {1, -1, 1, -1, 1, -1, 0, 0}; int kmx[] = {-1, -1, 1, 1, 2, -2, 2, -2}; int kmy[] = {2, -2, 2, -2, -1, -1, 1, 1}; int bishopX[] = {-1, 1, -1, 1}; int bishopY[] = {-1, -1,...
### Prompt Create a solution in CPP for the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given ...
#include <bits/stdc++.h> using namespace std; bool comp(long long x, long long y) { return x > y; } int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int main() { int format; cin >> format; string clock; cin >> clock; string hour, mins; hour += clock[0]; hour += clock[1]; m...
### Prompt In CPP, your task is to solve the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given...
#include <bits/stdc++.h> using namespace std; int N, H, M; int main() { scanf("%d%d:%d", &N, &H, &M); if (N == 24) { if (H / 10 >= 3) H %= 10; if (H / 10 == 2 && H % 10 >= 4) H %= 10; } else { if (H / 10 >= 2) { if (H % 10 == 0) H = H % 10 + 10; else H %= 10; } if (...
### Prompt Please formulate a Cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int h1 = (int)(s[0] - '0'); int h2 = (int)(s[1] - '0'); int m1 = (int)(s[3] - '0'); int m2 = (int)(s[4] - '0'); if (n == 12) { if (m1 > 5) m1 = 1; if (h1 >= 2) { if (h2 == 0) h1 = 1; ...
### Prompt In cpp, your task is to solve the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const double EPS = 1e-9; const double pi = acos(-1.0); const long long MAXN = (long long)1e6 + 7; const long long INF = (long long)1e9 + 7; const long long LINF = (long long)1 << 63 - 5; const long long MOD = (long long)2147482661...
### Prompt Please formulate a Cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a == 12) { string t; cin >> t; if (t[0] > '1' && t[1] != '0') t[0] = '0'; if (t[0] != '1' && t[1] == '0') t[0] = '1'; if (t[0] == '1' && t[1] > '2') t[0] = '0'; if (t[3] > '5') t[3] = '0'; cout << t << endl...
### Prompt Please provide a Cpp coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { #pragma warning(disable : 4996) int n; scanf("%d", &n); string s; getline(cin, s); getline(cin, s); int ch; if (n == 24) { ch = (s[0] - '0') * 10 + (s[1] - '0'); if (ch > 23) { s[0] = '0'; } ch = (s[3] - '0') *...
### Prompt Develop a solution in CPP to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a, b; scanf("%d:%d", &a, &b); if (b >= 60) { b = b % 10; } if (t == 12 && a >= 1 && a <= 12) { } else if (t == 12) { if (a % 10 == 0) { a = 10; } else { a = a % 10; } } if (t == 24 && a >= t) ...
### Prompt Please create a solution in cpp to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int main() { int f, a, b; char c; scanf("%d", &f); scanf("%02d:%02d", &a, &b); if (b > 59) b = b % 10; if (a > f || a == 24) { a = a % 10; } if (f == 12 && a == 0) { a = 10; } printf("%02d:%02d", a, b); return 0; }
### Prompt Please formulate a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; if (n == 12) { if (s[0] > '1' && s[1] == '0') s[0] = '1'; else if (s[0] == '1' && s[1] > '2') s[1] = '0'; else if (s[0] == '0' && s[1] == '0') s[1] = '1'; else if (s[0] > '1' && s[...
### Prompt Create a solution in cpp for the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given ...
#include <bits/stdc++.h> using namespace std; int main() { int n; string st; cin >> n >> st; if (n == 24) { if (10 * (st[0] - '0') + st[1] - '0' >= 24) { st[0] = '0'; } } else if (n == 12) { if (10 * (st[0] - '0') + st[1] - '0' > 12) { st[0] = '0'; } if (10 * (st[0] - '0') + st...
### Prompt Generate a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a, b, c, d, e; cin >> a >> b >> c >> d >> e; char p, q, r, s; int cnt = 5; if (n == 24) { for (int i = 0; i < 24; ++i) { for (int j = 0; j < 60; ++j) { int cnt1 = 0; if ((int)(a) - (int)('0') != i / ...
### Prompt Please provide a cpp coded solution to the problem described below: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int main() { int format, hour, minute; scanf("%d", &format); scanf("%d:%d", &hour, &minute); int h1 = hour / 10; int h2 = hour % 10; int m1 = minute / 10; int m2 = minute % 10; if (m1 > 5) m1 = 0; switch (format) { case 12: if (hour > 12) { ...
### Prompt Create a solution in Cpp for the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; string s; cin >> n; cin >> s; if (s[3] >= '6' && s[3] <= '9') s[3] = '0'; int h = (s[0] - '0') * 10 + (s[1] - '0'); if (n == 24) { if (h >= n) s[0] = '0'; } else { if (h % 10 == 0) ...
### Prompt Your task is to create a cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. Yo...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); string t; cin >> t; int _max = 5; string ans; for (int i = 0; i < 24; i++) for (int k = 0; k < 60; k++) { string a = to_string(i); string b = to_string(k); if (a.size() < 2) a.insert(a.begin(), '0'); ...
### Prompt Construct a CPP code solution to the problem outlined: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are giv...
#include <bits/stdc++.h> using namespace std; int main() { int f; string s; cin >> f >> s; int hours = (s[0] - '0') * 10 + (s[1] - '0'), minutes = (s[3] - '0') * 10 + (s[4] - '0'); if (minutes > 59) minutes %= 10; if (f == 12) { if (hours == 0) hours = 1; else if (hours > 12) { if ...
### Prompt Your challenge is to write a cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59....
#include <bits/stdc++.h> using namespace std; int main() { int f, m, h; char c; cin >> f; cin >> h >> c >> m; if (m >= 60) { m = 50 + (m % 10); } if (f == 12) { if (h > 12 || h == 0) { h = h % 10; if (h == 0) h = 10; } } else { if (h > 23) { h = (h % 10); } } if...
### Prompt Create a solution in cpp for the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given ...
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const long long linf = 1ll << 60; const double dinf = 1e10; inline long long read() { bool f = 0; long long x = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') { f = 1; c = getchar(); ...
### Prompt Generate a cpp solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a ...
#include <bits/stdc++.h> using namespace std; int main() { int c; cin >> c; int a, b; scanf("%02d:%02d", &a, &b); if (b >= 60) { b %= 10; } if (a > c || a == 24) { a %= 10; } if (c == 12 and a == 0) { a = 10; } printf("%02d:%02d\n", a, b); }
### Prompt Please formulate a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; void solve() { int format; cin >> format; string s; cin >> s; int h = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[3] - '0') * 10 + (s[4] - '0'); if (m >= 60) { m = m % 10; } if (format == 12) { if (h == 0) { h = 1; } else if (h > 12) { ...
### Prompt Please formulate a CPP solution to the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are ...
#include <bits/stdc++.h> using namespace std; int n; string second; string toStr(int hr, int mn) { string hrs = to_string(hr); string mns = to_string(mn); if (hr < 10) hrs = "0" + hrs; if (mn < 10) mns = "0" + mns; return hrs + ":" + mns; } int main() { string arr[5]; int first; cin >> first; cin >> s...
### Prompt Construct a Cpp code solution to the problem outlined: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are giv...
#include <bits/stdc++.h> int main() { int fmt, h, m; scanf("%d", &fmt); scanf("%d:%d", &h, &m); if (m >= 60) m = m % 10; if (fmt == 24) { if (h >= 24) h = h % 10; } else if (h > 12 || h == 0) { if (h % 10 != 0) h = h % 10; else h = 10; } printf("%02d:%02d\n", h, m); return 0; }...
### Prompt In cpp, your task is to solve the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool upmin(T1 &x, T2 v) { if (x > v) { x = v; return true; } return false; } template <class T1, class T2> bool upmax(T1 &x, T2 v) { if (x < v) { x = v; return true; } return false; } void solve() { int N; cin >>...
### Prompt Create a solution in Cpp for the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given ...
#include <bits/stdc++.h> using namespace std; int main() { int n, r = 0; int tab[100000]; char a, b, c, d; scanf("%d\n", &n); scanf("%c%c:%c%c", &a, &b, &c, &d); if (c - 48 > 5) { c = '0'; } if (n == 24 && (a - 48) > 2) { a = '1'; } if ((a - 48) == 2 && (b - 48) >= 4) { b = '3'; } if...
### Prompt In CPP, your task is to solve the following problem: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given...
#include <bits/stdc++.h> using namespace std; long long int curr[200005], mx[200005], arr[200005], n, inf = -9999999999, m = -9999999999; vector<long long int> v[200005]; long long int dfs(long long int a, long long int p) { curr[a] = arr[a]; for (auto it : v[...
### Prompt Construct a cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int inf = 2e9; const int mod = 1e9 + 7; const long long INF = 2e18; int n; vector<long long> g[N], h[N]; long long a[N], c[N], d[N], res = -INF; char u[N]; void dfs(int v, int p = 0) { u[v] = 1; for (int i = 0; i < int(g[v].size()); ++i) { ...
### Prompt Generate a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; vector<long long> V[200100]; long long D[200100][3], sum[200100], a[200100], N; void DFS(long long n, long long p) { long long i, j, max2, max11, max12, max11w; max2 = max11 = max12 = -4e18; sum[n] += a[n]; for (i = 0; i < V[n].size(); i++) { if (V[n][i] == p) c...
### Prompt Your challenge is to write a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } vector<long long int> v[2000...
### Prompt Please formulate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > v; vector<long long int> gfts, costs, sub_total; long long int ans = LLONG_MIN; bool flag = 0; void dfs(long long int curr, long long int par) { vector<long long int> sub_tree; long long int total = 0; for (long long int i = 0; i < v[cur...
### Prompt In cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; int n; int a[200010]; vector<vector<int> > V; long long ans = -2e9 - 1; pair<long long, long long> dfs(int idx, int p) { long long sum = 0; long long mx = -2e9 - 1; pair<long long, long long> p2; long long m1 = -2e9 - 1, m2 = -2e9 - 1; long long maxx = -2e9 - 1; ...
### Prompt Please provide a CPP coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const long long INF = 1000000000000000000; vector<int> G[maxn], son[maxn]; long long val[maxn], sum[maxn], maxsum[maxn], vis[maxn]; long long dfs(int u) { vis[u] = 1; sum[u] = val[u]; maxsum[u] = -INF; for (int i = 0; i < G[u].size(); i...
### Prompt Develop a solution in cpp to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> struct State { bool impossible; long long max_sum; long long max; long long sum; }; void dfs(int u, int p, const std::vector<std::vector<int> > &adjList, const std::vector<int> &a, std::vector<State> &states) { State &curState = states[u]; curState.sum = a[u]; for (auto v...
### Prompt Please create a solution in cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int lim = 2e5 + 50; const long long inf = 1e15; long long ret = -inf; int n; vector<long long> a(lim, 0), sum(lim, 0), mx(lim, 0); vector<vector<int>> adj(lim); void evalmx(int cur, int par) { sum[cur] = a[cur], mx[cur] = -inf; for (auto nxt : adj[cur]) { if (...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << "," << p.second << "}"; return os; } const long long N = 2e5 + 5; const long long oo = 1e9 + 7; long long n, ans = LONG_MIN; vector<long long> g[N]; long long...
### Prompt Construct a cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; string vow = "aeiou"; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; const long double pie = 3.14159265358979; const long long mod = 1e9 + 7; int n; vect...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> static const long long INF64 = 1LL << 61; static const int MAXN = 2e5 + 8; static const int MAXM = 4e5 + 8; template <typename T> inline void upd_max(T &var, const T val) { if (var < val) var = val; } int n, a[MAXN]; long long subt[MAXN]; int head[MAXN], dest[MAXM], next[MAXM]; std::multiset<...
### Prompt Please create a solution in Cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; } template <class T> void amin(T &a, T v) { if (a > v) a = v; } template <class T> void amax(T &a, T v) { if (a < v) a = v; } int ROUND(double x) { return (int)(x...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long INF = 1e16; long long a[N], sum[N], best[N]; bool seen[N] = {0}; vector<int> g[N]; void findSums(int st); long long solve(int cur); int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i < n; ...
### Prompt Your task is to create a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 7, LINF = 8e18; vector<long long> g[MAXN]; long long a[MAXN]; long long size[MAXN]; pair<long long, long long> dp[MAXN]; pair<long long, long long> add(pair<long long, long long> a, long long val) { if (val == -LINF) return a; if (a.first ==...
### Prompt Please formulate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int MAXN = 2e5; vector<int> G[MAXN]; int N, A[MAXN]; long long best1[MAXN], best2[MAXN], w[MAXN]; void dfs(int v, int p = -1) { best2[v] = -INF; long long b1 = -INF, b2 = -INF; w[v] = A[v]; for (int i = 0; i < (int)G[v].size(); i++)...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n, a[maxn]; int head[maxn], cnt; long long s[maxn], dp[maxn][2]; struct edge { int to, next; } e[maxn << 1]; void adde(int u, int v) { e[++cnt].to = v; e[cnt].next = head[u]; head[u] = cnt; } void dfs1(int u, int fa) { s[u] = a[u]; ...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; vector<int> adj[205000]; long long a[205000]; long long val[205000]; long long maxVal[205000]; bool vis[205000]; void dfs(int v) { vis[v] = 1; val[v] = a[v]; maxVal[v] = LLONG_MIN; for (int i = 0; i < adj[v].size(); i++) { if (vis[adj[v][i]] == 0) { dfs(ad...
### Prompt Please formulate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 2e6 + 7, mod = 1000000007, M = 2e9; const long long MAX = 1e18, V = 1e16; int T, n, u, v, t[N][2]; long long a[N], ans; vector<int> g[N], tree; struct seg_tree { long long s[N]; void build(int from = 0, int to = T - 1, int i = 0...
### Prompt Your task is to create a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long inf = 1e17; int n; int arr[N]; long long sub[N]; long long mex[N]; int a, b; vector<int> v[N]; long long ans; void dfs(int node, int parent) { sub[node] = arr[node]; mex[node] = -inf; long long val1 = -(inf + inf); long long va...
### Prompt Your challenge is to write a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long mod = 1e9 + 7; const int N = 1e5 + 10; long long arr[200010]; vector<int> edges[200010]; vector<int> tree[200010]; vector<long long> calc[200010]; long long value[200010]; long long maxval[200010]; void maketree(int par, int root)...
### Prompt Generate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; const long long inf = 2e15; const int N = 2e5 + 20; vector<int> e[N]; long long a[N], sum[N]; long long dp[N]; int n; void dfs(int u, int fa) { sum[u] = a[u]; dp[u] = -inf; for (int i = 0; i < e[u].size(); i++) { int v = e[u][i]; if (v != fa) { dfs(v, u)...
### Prompt Please create a solution in Cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; void calculate_sum_pleaseness(vector<vector<int> >& Tree, vector<long long int>& pleaseness, vector<long long int>& max_pleaseness, int root, int parent) { long long int max_child_pl...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; vector<int> lis[200000]; int a[200000]; long long maxs, inf = -100000000000, result = inf; long long dfs(int cur, int parent) { long long res = a[cur]; long long first = inf; long long second = inf; for (int i = 0; i < lis[cur].size(); i++) { if (lis[cur][i] == ...
### Prompt Create a solution in cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void ma...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; vector<long long> mx(2 * 100002); vector<long long> siz(2 * 100002, 0); vector<long long> a(2 * 100002); vector<long long> total(2 * 100002); vector<long long> v[2 * 100002]; long long n; void dfs(long long v1, long long p) { siz[v1] = a[v1]; mx[v1] = -LLONG_MAX; for ...
### Prompt In cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; long long int a[1000001]; long long int val[1000001]; vector<long long int> v[1000001]; long long int ans = -10000000000000000; long long int f = 0; long long int vis[1000001]; long long int d(long long int p) { long long int i, j, q; vis[p] = 1; val[p] += a[p]; for...
### Prompt Generate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; const int N = 3e5; const long long inf = 1e15; long long sum[N], mx[N], a[N], ans = -inf; int n; vector<int> g[N]; bool used[N]; void dfs1(int u) { used[u] = true; sum[u] = a[u]; mx[u] = -inf; vector<long long> v; for (int i = 0; i < g[u].size(); i++) { int to...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const long long int M = -1e16 - 18; const long long int N = 2e5; long long int power(long long int x, long long int y, long long int M = ::M) { x %= M; long long int ans = 1; while (y) { if (y & 1) ans = (ans * x) % M; y >>= 1LL; x = (x * x) % M; } ret...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; int32_t main(void) { srand(time(0)); cout << fixed << setprecision(7); cerr << fixed << setprecision(7); long long n; ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n; static vector<long long> s[1 << 20]; static long long v[1 << 20]; static long long ...
### Prompt Please provide a Cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; long long int dp[200005], ans[200005], sum[200005], a[200005]; vector<int> v[200005]; void solve(long long int x, long long int p) { int s, fi, si, i; s = v[x].size(); sum[x] = a[x]; ans[x] = -1000000000000000007; dp[x] = -1000000000000000007; fi = si = -1; fo...
### Prompt Create a solution in Cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; int n; vector<int> nodes[200001]; int val[200001]; long long anss = -1111111111111; long long sum[200001]; int in[200001]; pair<long long, long long> maxs[200001]; priority_queue<pair<long long, int>> resss; long long dfs(int node) { if (node == 8) { int aa = 0; } ...
### Prompt Your challenge is to write a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const long long MOD = (long long)1e9 + 7; vector<int> g[MAXN]; long long a[MAXN]; long long dp[MAXN]; long long sum[MAXN]; bool used[MAXN]; int n; long long ans = -1e16; void dfs(int v) { used[v] = 1; int sz = g[v].size(); if (sz == 1 && v !=...
### Prompt Your challenge is to write a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; constexpr long long maxn = 2e5 + 5, inf = 1ll << 61; long long n, m, k, a[maxn], f[maxn], res[maxn], mm, ans = -inf; long long dp[maxn]; vector<long long> e[maxn]; void dfs(long long u, long long fa) { dp[u] = -inf; f[u] = a[u]; for (auto v : e[u]) { if (v == fa) ...
### Prompt Develop a solution in Cpp to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; std::vector<vector<int> > adj(200005), child(200005); std::vector<long long> v; int n, x, y; long long a[200005]; long long dp[200005], sum[200005]; bool cmp(long long a, long long b) { return a > b; } void dfs(int u, int p) { sum[u] += a[u]; dp[u] = -999999999999; fo...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > matMul(vector<vector<long long int> > A, vector<vector<long long int> > B, long long int m) { int r1 = A.size(), r2 = B.size(), c1 = A[0].size(), c2 = B[0].size(); ...
### Prompt Please formulate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; int const N = 2 * 100 * 1000 + 16; int n; long long mx[N]; long long sum[N]; long long best = -8e18; vector<int> g[N]; void dfs(int u = 1, int p = 0) { sum[u] = mx[u]; mx[u] = -9e18; long long x = -4e18, y = -4e18; for (int v : g[u]) { if (v == p) continue; ...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; vector<int> vec[200005]; int arr[200005]; long long ans = -0x7f7f7f7f, sign[200005], MAX = -1, vis[200005]; long long Max(long long a, long long b) { return a > b ? a : b; } long long dfs(int u, int pre) { long long tmp = arr[u], cnt; for (int i = 0; i < vec[u].size(); ...
### Prompt Create a solution in Cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; int arr[200005]; long long sum[200005], mxn[200005]; vector<int> vi[200005]; long long ans = -1e18, mm = -1e18; void sol(int node, int par) { sum[node] = arr[node]; mxn[node] = mm; for (auto it : vi[node]) { if (it == par) continue; sol(it, node); sum[node...
### Prompt Please create a solution in cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; struct edge { int s, t, next; } e[400010]; int head[200010], cnt; void addedge(int s, int t) { e[cnt].s = s; e[cnt].t = t; e[cnt].next = head[s]; head[s] = cnt++; e[cnt].s = t; e[cnt].t = s; e[cnt].next = head[t]; head[t] = cnt++; } int n, u, v; long long ...
### Prompt Construct a CPP code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> int a[200010]; using namespace std; int visit[200010]; long long INF = -400000000000010; vector<int> edge[200010], edge0[200010]; long long sum[200010], maxsub[200010]; long long m3 = INF; void dfs0(int x) { visit[x] = 1; for (int i = 0; i < edge0[x].size(); i++) { if (visit[edge0[x][i]...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const int MN = 200 * 1000 + 200; vector<int> adj[MN]; long long dpd[MN]; long long dpdmx[MN]; long long dpu[MN]; long long a[MN]; long long dps[MN][2]; void dfs1(int v, int p) { dps[v][0] = -1e17; dps[v][1] = -1e17; dpd[v] += a[v]; for (int u : adj[v]) { if (u !...
### Prompt Please provide a Cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; vector<long long> sum(200010, 0); long long ans = -100000000000000010; long long recursion(vector<int> v[], int k, int parent) { long long y; long long maxA = -100000000000000010, maxB = -100000000000000010, maxi = -100000000000000010; for (int i = 0; i < ...
### Prompt Please provide a cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; long long p[200005]; vector<long long> v[200005]; struct node { long long sum; long long mx; }; long long mxl[200005], smxl[200005]; node dfs(long long u, long long vis[], long long level) { vis[u] = 1; node cur; cur.sum = p[u]; cur.mx = p[u]; if (v[u].size() ...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 7; const int N = 2e5 + 3; long long ans = -INF; int n; long long a[N]; vector<int> g[N]; long long mx = -INF; void DFS1(int u, int par) { for (size_t i = 0; i < g[u].size(); ++i) { int v = g[u][i]; if (v != par) { DFS1(v, u); ...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const int dfs_white = 0; const int dfs_grey = 1; const int dfs_black = 2; const int maxn = 200000; const long long inf = 2000000000000000LL; int v[maxn + 5]; long long dp[maxn + 5]; long long sum[maxn + 5]; vector<int> adjList[maxn + 5]; int n; int visited[maxn + 5]; long l...
### Prompt Your challenge is to write a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const long long minn = -1e18; long long c[200005], best[200005], sum[200005]; long long head[200005], m, sum_; struct edge { long long to, next; } e[200005 * 2]; void add(long long f, long long t) { sum_++; e[sum_].to = t; e[sum_].next = head[f]; head[f] = sum_; }...
### Prompt Please formulate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; int n; int a[200005]; struct edge { int to, nxt; } e[2 * 200005]; int h[200005], tot; void add_edge(int x, int y) { e[++tot].to = y; e[tot].nxt = h[x]; h[x] = tot; } long long f[200005][2]; long long s[200005]; long long ans; void dfs(int x, int fa) { s[x] = a[x];...
### Prompt Please create a solution in cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; multiset<long long> s[200005]; vector<long long> v[200005]; long long n, x, y, sum, sc[200005], a[200005], sol, i; void df(int nod, int tata) { sc[nod] = a[nod]; for (auto it : v[nod]) if (it != tata) { df(it, nod); sc[nod] += sc[it]; for (auto jt ...
### Prompt Please create a solution in CPP to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; int n; const int maxn = 300000; int a[maxn]; vector<int> edges[maxn]; long long sum[maxn]; long long maxsum[maxn][3]; long long ans[maxn]; long long output; const long long ninf = 0xA000000000000000; void dfs(int p, int cur) { for (vector<int>::iterator iter = edges[cur]....
### Prompt Construct a cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const long long INF = -1e13 - 7; int n; long long d[maxn], dp[maxn]; long long ans = INF; vector<int> G[maxn]; void dfs(int u, int fa) { for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (v == fa) continue; dfs(v, u); d[...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; void read(long long int n = 10) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; } long long int M = 1e9 + 7; long long int M1 = 998244353; long long int n, a, b, lv, rv; vector<long long int> values; vector<pair<long long i...
### Prompt Create a solution in cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; long long a[200002]; long long g[200002]; long long s[200002]; long long ans = LLONG_MIN; vector<long long> v[200002]; long long dfs(int p, int fr) { g[p] = a[p]; s[p] = LLONG_MIN; for (auto it : v[p]) { if (it == fr) continue; g[p] += dfs(it, p); s[p] = m...
### Prompt In cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...