QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291921 | #7118. Closing Time | Feet_McYeet | Compile Error | / | / | C++17 | 2.3kb | 2023-12-27 13:38:48 | 2023-12-27 13:38:48 |
Judging History
你现在查看的是测评时间为 2023-12-27 13:38:48 的历史记录
- [2024-04-28 08:00:24]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-27 13:38:48]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-27 13:38:48]
- 提交
answer
// #include "closing.h"
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx2")
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define el << '\n'
#define nl cout << '\n'
#define spc << ' '
#define forn(i,n) for (int i=0; i<n; i++)
#define forl(i,s,e) for (int i=s; i<e; i++)
#define pb push_back
#define fi first
#define se second
#define rsz resize
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
int max_score(int N, int X, int Y, ll K, int U[], int V[], int W[]) {
pll dis[N];
vector<pll> adj[N];
struct st {
int cn, pn; ll d; bool p;
};
// void dfs(int cn, int pn, ll d, bool p) {
// if (p) dis[cn].se = d;
// else dis[cn].fi = d;
// for (pii i : adj[cn]) if (i.fi != pn) dfs(i.fi, cn, d+i.se, p);
// }
forn(i,N-1) {
adj[U[i]].pb({V[i], W[i]});
adj[V[i]].pb({U[i], W[i]});
}
vector<st> stk;
stk.pb({X, -1, 0, 0});
while (sz(stk)) {
st a = stk.back();
stk.pop_back();
if (a.p) dis[a.cn].se = a.d;
else dis[a.cn].fi = a.d;
for (pii i : adj[a.cn]) if (i.fi != a.pn) stk.pb({i.fi, a.cn, a.d+i.se, a.p});
}
stk.pb({Y, -1, 0, 1});
while (sz(stk)) {
st a = stk.back();
stk.pop_back();
if (a.p) dis[a.cn].se = a.d;
else dis[a.cn].fi = a.d;
for (pii i : adj[a.cn]) if (i.fi != a.pn) stk.pb({i.fi, a.cn, a.d+i.se, a.p});
}
forn(i,N) if (dis[i].fi < dis[i].se) swap(dis[i].fi, dis[i].se);
sort(dis,dis+N);
bool u[N];
forn(i,N) u[i] = false;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
priority_queue<pair<ll, int>> rpq;
// forn(i,N) cout << dis[i].fi spc << dis[i].se el;
// nl;
forn(i,N) pq.push({dis[i].se, i});
int tot = 0;
while (1) {
ll temp = K - pq.top().fi;
if (temp < 0) break;
u[pq.top().se] = 1;
rpq.push(pq.top());
pq.pop();
K = temp;
tot++;
}
// cout << K spc << tot el;
int ans = tot;
forn(i,N) {
if (u[i]) {
K += dis[i].se;
tot--;
}
K -= dis[i].fi;
tot += 2;
bool temp = false;
while (K<0) {
if (!sz(rpq)) {
temp = true;
break;
}
auto cn = rpq.top();
rpq.pop();
if (cn.se <= i) continue;
tot--;
K += cn.fi;
}
if (temp) break;
ans = max(ans, tot);
}
return tot;
}
详细
/usr/bin/ld: /tmp/ccrtZs7n.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