QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789745#7588. Monster HunterKFCWA 436ms17524kbC++112.2kb2024-11-27 21:40:112024-11-27 21:40:14

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 21:40:14]
  • 评测
  • 测评结果:WA
  • 用时:436ms
  • 内存:17524kb
  • [2024-11-27 21:40:11]
  • 提交

answer

// Hydro submission #674721369592d6097b8707e5@1732714807284
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
typedef pair<int, int> PP;
typedef double db;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
vector<int> v[N];
int fa[N], n, a[N], b[N], pos[N], fa1[N];
int check(int i) {
    if(a[i] <= b[i]) return 1;
    return 2;
}
struct node {
    int x;
    bool operator < (const node k) const{    
        int wasd = k.x, dsaw = x;
        if(check(wasd) != check(dsaw)) return check(wasd) < check(dsaw);
        else {
            if(check(wasd) & 1) return a[wasd] < a[dsaw];
            else return b[wasd] > b[dsaw];
        }
    }
};
void findfa(int x, int ffa) {
    fa1[x] = ffa;
    for(int wasd : v[x]) {
        if(wasd == ffa) continue;
        findfa(wasd, x);
    }
}
int find(int x) {
    if(fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}

priority_queue<node> q;
void merge(int x, int y) {
    int now = 0, mi = 0;
    now -= a[x], mi = min(mi, now);
    now += b[x], mi = min(mi, now);
    now -= a[y], mi = min(mi, now);
    now += b[y], mi = min(mi, now);
    // cout << now << endl;
    a[x] = -mi;
    b[x] = now - mi;
    fa[find(y)] = find(x);
}
signed main() {
    // freopen("tree.in", "r", stdin);
    // freopen("tree.out", "w", stdout);
    // freopen("tree.out", "w", stdout);
    int T; cin >> T; while(T --) {
        cin >> n;
        int ans = 0;
        a[1] = b[1] = 0;
        for(int i = 2; i <= n; i ++) {
            scanf("%lld%lld", &a[i], &b[i]);
        }
        for(int i = 1; i < n; i ++) {
            int wasd, dsaw; scanf("%lld%lld", &wasd, &dsaw);
            v[wasd].push_back(dsaw), v[dsaw].push_back(wasd);
            fa[i] = i;
        }
        fa[n] = n, findfa(1, 0);
        for(int i = 2; i <= n; i ++) q.push({i});
        while(!q.empty()) {
            int i = q.top().x; q.pop();
            int f = find(fa1[i]);
            merge(f, i);
            // cout << f << ' ' << a[1] << ' ' << b[1] << endl;
        }
        cout << a[1] << endl;
        for(int i = 1; i <= n; i ++) v[i].clear();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8200kb

input:

1
4
2 6
5 4
6 2
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 436ms
memory: 17524kb

input:

10
50000
112474 198604
847262 632597
871374 962220
971398 284540
10360 695245
43233 569941
64019 203468
598469 997911
41841 657552
333198 936119
546370 180011
58831 901040
959767 396595
710441 277461
429299 209831
494164 138327
393982 581911
993164 617488
108113 160310
55841 611360
301395 291074
149...

output:

63495498
541156749
191617241
177090559
630213926
27231993394
19064806867
37194996614
84584890
84657366

result:

wrong answer 5th numbers differ - expected: '383609891', found: '630213926'