米哈游 树中abb类型个数,求大佬解释一下为什么只过了95%

#include <bits/stdc++.h>
using namespace std;
struct Node {
    char        val;
    set<Node *> next;
    int         notEqual;
    Node(int v) : val(v), notEqual(0) {}
};

int main() {
    int    n   = 0;
    int    cur = 0, next = 0;
    string val;
    cin >> n;
    cin >> val;
    vector<Node *>   tree(n + 1);
    set<vector<int>> candicates;

    for (int i = 1; i <= n; ++i) {
        tree[i] = new Node(val[i - 1]);
    }
    for (int i = 1; i < n; ++i) {
        cin >> cur >> next;
        if (tree[cur]->next.find(tree[next]) != tree[cur]->next.end())
            continue;
        tree[cur]->next.insert(tree[next]);
        tree[next]->next.insert(tree[cur]);
        if (tree[cur]->val == tree[next]->val) {
            candicates.insert({cur, next});
        }
        else {
            ++tree[cur]->notEqual;
            ++tree[next]->notEqual;
        }
    }
    int ans = 0;
    for (auto &candicate : candicates) {
        ans += tree[candicate[0]]->notEqual += tree[candicate[1]]->notEqual;
    }
    cout << ans << endl;
    return 0;
}

#米哈游笔试#
全部评论
1e5个节点连三个,应该会爆int,得开longlong,我也是95。。
点赞 回复 分享
发布于 2022-08-07 22:35
溢!悟!
点赞 回复 分享
发布于 2022-08-07 22:24
同求
1 回复 分享
发布于 2022-08-07 22:23
看来都95啊😅
点赞 回复 分享
发布于 2022-08-07 23:27
同求
点赞 回复 分享
发布于 2022-08-07 22:24

相关推荐

完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 10:39
一个证都没&nbsp;我能填什么
凉风落木楚山秋:空白不是说你没证吧,有实践也行
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务