QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291896 | #7118. Closing Time | danielkou5855 | Compile Error | / | / | C++17 | 2.6kb | 2023-12-27 12:54:53 | 2023-12-27 12:54:54 |
Judging History
你现在查看的是测评时间为 2023-12-27 12:54:54 的历史记录
- [2024-04-28 07:59:56]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-27 12:54:54]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-27 12:54:53]
- 提交
answer
// Source: https://usaco.guide/general/io
#include "closing.h"
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <algorithm>
#define int long long
#define double long double
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define edge pair<int, int>
using namespace std;
vector<vector<edge>> adj;
vector<int> psum1, psum2;
int NO1, NO2;
void gen(int c, int p, int flag) {
if (p != -1 && flag == 0 && c == NO1) {
return;
}
if (p != -1 && flag == 1 && c == NO2) {
return;
}
for (auto n : adj[c]) {
if (n.first != p) {
if (flag == 0) {
psum1[n.first] = psum1[c] + n.second;
} else {
psum2[n.first] = psum2[c] + n.second;
}
gen(n.first, c, flag);
}
}
}
struct cmp {
bool operator()(const array<int, 3> &x, const array<int, 3> &y) const {
return x[0] > y[0];
}
};
struct cmp2 {
bool operator()(const array<int, 3> &x, const array<int, 3> &y) const {
return x[0] < y[0];
}
};
int max_score(int N, int X, int Y, long long K, int U[], int V[], int W[]) {
adj.resize(N); psum1.resize(N); psum2.resize(N); NO1 = X, NO2 = Y;
for (int i = 0; i < N; i++) {
adj[i].clear(); psum1[i] = psum2[i] = 0;
}
for (int i = 0; i < N - 1; i++) {
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
}
// gen psum
gen(X, -1, 0); gen(Y, -1, 1);
// do the cardboard box thing
vector<int> a(N), b(N);
for (int i = 0; i < N; i++) {
a[i] = min(psum1[i], psum2[i]);
b[i] = max(psum1[i], psum2[i]);
// cout << psum1[i] << " " << psum2[i] << "\n";
// cout << a[i] << " " << b[i] << "\n";
}
vector<int> status(N, 0); // 0 = nothing, 1 = one only, 2 = both
// {cost, vertex, index}
priority_queue<array<int, 3>, vector<array<int, 3>>, cmp> pq;
vector<array<int, 3>> trust;
for (int i = 0; i < N; i++) {
trust.push_back({a[i], i, 0});
}
int ans = 0; int ct = 0;
sort(all(trust), cmp2());
while (ans <= K) {
if (ct == N) {
return ct;
}
if (ans + trust[ct][0] <= K) {
ans += trust[ct][0]; status[trust[ct][1]]++;
pq.push({b[trust[ct][1]] - a[trust[ct][1]], trust[ct][1], 1}); ct++;
} else {
break;
}
}
while (!pq.empty()) {
auto t = pq.top(); pq.pop();
bool fin = true;
if (ans + t[0] <= K) {
// check if all adj are activated
for (auto n : adj[t[1]]) {
if (!status[n.first]) {
fin = false;
}
}
if (fin) {
ans += t[0]; status[t[1]]++; ct++;
}
}
}
return ct;
}
Details
/usr/bin/ld: /tmp/cczvYkLt.o: in function `main': implementer.cpp:(.text.startup+0x775): undefined reference to `max_score(int, int, int, long long, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)' collect2: error: ld returned 1 exit status