QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292427 | #7118. Closing Time | AuroraH456 | Compile Error | / | / | C++14 | 3.7kb | 2023-12-28 04:46:15 | 2024-04-28 08:03:40 |
Judging History
你现在查看的是最新测评结果
- [2024-04-28 08:03:40]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-28 04:46:16]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-28 04:46:15]
- 提交
answer
#include <bits/stdc++.h>
#define ll long long
#define SZ(X) (int)(X.size())
#define MAX 200005
#define VAL 1000006
#define pii pair <int,int>
#define node first
#define wei second
using namespace std;
struct Data{
ll cost;
int score;
Data operator + (const Data & other) const {
return {cost+other.cost, score+other.score};
}
void operator += (const Data & other){
*this = *this + other;
}
};
struct SegmentTree{
Data data[VAL*4];
int len = VAL-1;
Data merge(Data x, Data y){ // change
return x+y;
}
void initialize(int loc, int le, int ri, Data arr[]){
if (le == ri) data[loc] = arr[le];
else {
int mid = (le+ri)/2;
initialize(loc*2, le, mid, arr);
initialize(loc*2+1, mid+1, ri, arr);
data[loc] = merge(data[loc*2], data[loc*2+1]);
}
}
void update(int loc, int ind, int le, int ri, Data arr[]){
if (le == ri) data[loc] = arr[le];
else {
int mid = (le+ri)/2;
if (ind <= mid) update(loc*2, ind, le, mid, arr);
else update(loc*2+1, ind, mid+1, ri, arr);
data[loc] = merge(data[loc*2], data[loc*2+1]);
}
}
int query(ll targ, int loc, int le, int ri){ // binary search query
if (le == ri) return data[loc].score;
int mid = (le+ri)/2;
if (targ <= data[loc*2].cost) return query(targ, loc*2, le, mid);
else return query(targ-data[loc*2+1].cost, loc*2+1, mid+1, ri) + data[loc*2+1].score;
}
};
int caseNum;
int nodeNum, cityA, cityB;
ll lim;
vector <pii> edge[MAX];
ll dist[MAX][2];
int ans;
int a, b, c;
SegmentTree seg;
Data arr[VAL];
vector <pii> opt; // b (cost for reachable from both), a (cost for reachable from one)
void reset(){
for (int i = 0; i < nodeNum; i++){
edge[i].clear();
dist[i][0] = dist[i][1] = 0;
}
for (int i = 0; i < VAL; i++)
arr[i] = {0,0};
opt.clear();
ans = 0;
}
void dfs(int cur, int par, bool which){ // for each node, find distance from the two cities
for (pii nex : edge[cur]){
if (nex.node == par) continue;
dist[nex.node][which] = dist[cur][which] + nex.wei;
dfs(nex.node, cur, which);
}
}
void enumOverlap(){ // check options for overlap
for (int i = 0; i < nodeNum; i++){ // assume each node -> reachable to at most one city
opt.push_back({max(dist[i][0], dist[i][1]), min(dist[i][0], dist[i][1])});
arr[opt.back().second] += {opt.back().second, 1}; // put in a's
}
seg.initialize(1, 1, seg.len, arr);
sort(opt.begin(), opt.end()); // sort by max distance
ans = max(ans, seg.query(lim, 1, 1, seg.len));
//cout << seg.data[1].cost << " " << dist[1][1] << " " << ans << "\n";
Data defa = {0,0}; // default (pick none)
for (pii o : opt){ // each node before o -> reachable to at least one city
defa += {o.second, 1};
if (defa.cost > lim) return;
arr[o.second] += {-o.second, -1};
arr[o.first-o.second] += {o.first-o.second, 1};
ans = max(ans, seg.query(lim-defa.cost, 1, 1, seg.len)+defa.score);
}
}
void solve(){
cin >> nodeNum >> cityA >> cityB >> lim;
reset();
for (int i = 0; i < nodeNum-1; i++){
cin >> a >> b >> c;
edge[a].push_back({b, c});
edge[b].push_back({a, c});
}
dfs(cityA, -1, 0);
dfs(cityB, -1, 1);
enumOverlap();
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> caseNum;
while (caseNum--) solve();
return 0;
}
Details
/usr/bin/ld: /tmp/cczWVNTi.o: in function `main': answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/cchaaGwl.o:implementer.cpp:(.text.startup+0x0): first defined here /usr/bin/ld: /tmp/cchaaGwl.o: in function `main': implementer.cpp:(.text.startup+0x744): 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