int T; int y, m, d; int bg, ed; map<int, int> f; int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
boolcheck(int y) { return (y % 4 == 0 && y % 100) || y % 400 == 0; }
intget_day(int y, int m, int d) { int res = d; for (int i = 1; i < y; i++) { res += 365; if (check(i)) res++; } mon[2] = check(y)? 29 : 28; for (int i = 1; i < m; i++) res += mon[i]; return res; }
intdp(int x) { if (f.count(x)) return f[x]; int t = x, y, m, d; for (int i = 1; i <= 2024; i++) { if (t > 365 + check(i)) t -= 365 + check(i); else { y = i; break; } } mon[2] = check(y)? 29 : 28; for (int i = 1; i <= 12; i++) { if (t > mon[i]) t -= mon[i]; else { m = i, d = t; break; } } map<int, int> p; if (x + 1 <= ed) p[dp(x + 1)] = 1; if (x + mon[m] <= ed && mon[m % 12 + 1] >= d) { mon[2] = check(y)? 29 : 28; p[dp(x + mon[m])] = 1; } int sg = 0; while (p.count(sg)) sg++; return f[x] = sg; }
intmain() { cin >> T; while (T--) { cin >> y >> m >> d; bg = get_day(y, m, d), ed = get_day(2024, 8, 1); if (dp(bg)) cout << "YES" << endl; else cout << "NO" << endl; } return0; }
intmain() { cin >> n >> m; for (int i = 0; i < m; i++) { int x, a, b; cin >> a >> b >> x; w[i] = {a, b, x}; } sort(w, w + m, cmp); for (int i = 1; i <= n; i++) p[i] = i; int res = 0; for (int i = 0; i < m; i++) { int a = w[i].a, b = w[i].b; int fa = find(a), fb = find(b); if (fa == fb) { res = w[i].x; break; } if (!enemy[a]) enemy[a] = b; else p[find(enemy[a])] = fb; if (!enemy[b]) enemy[b] = a; else p[find(enemy[b])] = fa; } cout << res << endl; return0; }
structNode { int a, b, x; }; int n, m; Node w[N]; vector<int> h[N]; int color[N];
boolcmp(Node A, Node B) { return A.x < B.x; }
booldfs(int u, int c) { color[u] = c; for (int i = 0; i < h[u].size(); i++) { int j = h[u][i]; if (color[j] == c) returnfalse; elseif (!color[j]) if (!dfs(j, 3 - c)) returnfalse; } returntrue; }
boolcheck(int x) { for (int i = 1; i <= n; i++) { h[i].clear(); color[i] = 0; } map<pair<int, int>, int> p; for (int i = x + 1; i < m; i++) { int a = w[i].a, b = w[i].b; p[{a, b}] = p[{b, a}] = 1; } for (auto it: p) { int a = it.x.x, b = it.x.y; h[a].push_back(b); } bool flag = true; for (int i = 1; i <= n; i++) if (!color[i] && !dfs(i, 1)) { flag = false; break; } return flag; }
intmain() { cin >> n >> m; for (int i = 0; i < m; i++) { int x, a, b; cin >> a >> b >> x; w[i] = {a, b, x}; } sort(w, w + m, cmp); int l = -1, r = m - 1; while (l < r) { int mid = l + r >> 1; if (!check(mid)) l = mid + 1; else r = mid; } if (~l) cout << w[l].x << endl; else cout << 0 << endl; return0; }
#define int long long #define x first #define y second
usingnamespace std;
typedef pair<int, int> PII;
constint N = 1000010;
int n, m; vector<PII> h1[N], h2[N]; int d1[N], d2[N]; bool st[N];
voiddijkstra(int d[], vector<PII> h[]) { memset(st, false, sizeof st); priority_queue<PII, vector<PII>, greater<PII>> heap; for (int i = 2; i <= n; i++) d[i] = 1e18; heap.push({0, 1}); while (heap.size()) { auto t = heap.top(); heap.pop(); int ver = t.y; if (st[ver]) continue; st[ver] = true; for (int i = 0; i < h[ver].size(); i++) { int j = h[ver][i].x, dist = h[ver][i].y; if (d[j] > d[ver] + dist) { d[j] = d[ver] + dist; heap.push({d[j], j}); } } } }
signedmain() { cin >> n >> m; while (m--) { int a, b, c; cin >> a >> b >> c; h1[a].push_back({b, c}); h2[b].push_back({a, c}); } dijkstra(d1, h1); dijkstra(d2, h2); int res = 0; for (int i = 2; i <= n; i++) res += d1[i] + d2[i]; cout << res << endl; return0; }
voidbuild(int u, int l, int r) { if (l == r) tr[u] = {l, r, a[l]}; else { tr[u] = {l, r}; int mid = l + r >> 1; build(ls, l, mid), build(rs, mid + 1, r); pushup(u); } }
intquery(int u, int l, int r) { if (tr[u].l >= l && tr[u].r <= r) return tr[u].maxv; else { int res = 0; int mid = tr[u].l + tr[u].r >> 1; if (l <= mid) res = max(res, query(ls, l, r)); if (r > mid) res = max(res, query(rs, l, r)); return res; } return0; }
intmain() { read(n); for (int i = 1; i <= n; i++) read(a[i]); build(1, 1, n); read(q); while (q--) { int l, r; read(l), read(r); print(query(1, l, r)); printf("\n"); } return0; }
signedmain() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int res = 1; for (int i = 0; i < n; i++) res += abs(a[i] - a[(n + 1) / 2 - 1]); cout << res << endl; return0; }
signedmain() { cin >> T; while (T--) { cin >> n; int l = 0, r = 1e10; while (l < r) { int mid = l + r + 1 >> 1; if (mid * mid <= n) l = mid; else r = mid - 1; } cout << l << endl; } return0; }
#define int long long #define x first #define y second
usingnamespace std;
typedef pair<int, int> PII;
constint N = 10010;
int n, m; vector<PII> h[N]; int st, ed; int d[N];
intbfs() { for (int i = 1; i <= n; i++) d[i] = 1e18; d[st] = 0; queue<int> q; q.push(st); while (q.size()) { auto t = q.front(); q.pop(); for (int i = 0; i < h[t].size(); i++) { int j = h[t][i].x, dist = max(d[t], h[t][i].y); if (d[j] > dist) { d[j] = dist; q.push(j); } } } return d[ed]; }
signedmain() { cin >> n >> m; while (m--) { int a, b, c; cin >> a >> b >> c; h[a].push_back({b, c}), h[b].push_back({a, c}); } cin >> st >> ed; cout << bfs() << endl; return0; }