QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789682 | #7588. Monster Hunter | KFC | Compile Error | / | / | C++98 | 1.7kb | 2024-11-27 21:27:18 | 2024-11-27 21:27:25 |
Judging History
answer
// Hydro submission #67471e349592d6097b870662@1732714036389
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 1e5 + 10;
vector<int> v[N];
int rt[N];
void dfs(int x, int fa){
rt[x] = fa;
for(int y : v[x]){
if(y == fa) continue;
dfs(y, x);
}
}
int n;
struct Node{
int a, b, id, res;
bool operator < (const Node &A) const {
if(a > b && A.a <= A.b) return 1;//回血在前
if(a <= b && A.a > A.b) return 0;
if(a > b && A.a > A.b) return b <= A.b;
else return a > A.a;
}
}p[N];
bool vis[N];
int ans[N];
priority_queue<Node> q;
int find(int x) {
if(vis[rt[x]]) return rt[x] = find(rt[x]);
return rt[x];
}
signed main(){
freopen("tree.in", "r", stdin);
freopen("tree.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 2; i <= n; i++){
int a, b;
cin >> a >> b;
p[i] = Node{a, b, i, 0};
q.push(p[i]);
}
for(int i = 1; i < n; i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1, 0);
int cnt = 0;
while(!q.empty()){
auto now = q.top();
q.pop();
// cout << now.id << endl;
if(vis[now.id] || now.res != ans[now.id]) continue;
vis[now.id] = 1;
int x = now.id, fax = find(now.id);
int a = p[fax].a;
p[fax].a = max(p[fax].a, p[fax].a - p[fax].b + p[x].a);
p[fax].b = p[fax].b - a - p[x].a + p[x].b + p[fax].a;
if(fax > 1){
p[fax].res = ans[fax] = ++cnt;
q.push(p[fax]);
}
}
cout << p[1].a << endl;
cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
return 0;
}
詳細信息
answer.code: In function ‘void dfs(long long int, long long int)’: answer.code:11:17: warning: range-based ‘for’ loops only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 11 | for(int y : v[x]){ | ^ answer.code:11:20: error: forming reference to reference type ‘std::vector<long long int>&’ 11 | for(int y : v[x]){ | ^ answer.code: In function ‘int main()’: answer.code:42:20: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 42 | p[i] = Node{a, b, i, 0}; | ^ answer.code:54:14: error: ‘now’ does not name a type 54 | auto now = q.top(); | ^~~ answer.code:57:16: error: ‘now’ was not declared in this scope; did you mean ‘pow’? 57 | if(vis[now.id] || now.res != ans[now.id]) continue; | ^~~ | pow answer.code:58:13: error: ‘now’ was not declared in this scope; did you mean ‘pow’? 58 | vis[now.id] = 1; | ^~~ | pow answer.code:60:19: error: ‘fax’ was not declared in this scope; did you mean ‘fmax’? 60 | int a = p[fax].a; | ^~~ | fmax answer.code:34:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | freopen("tree.in", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ answer.code:35:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | freopen("tree.out", "w", stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~