PTA满树遍历求助--有个测试点错了

#include<bits/stdc++.h>
using namespace std;
vector<int> pre;
void dfs(vector<int>&arr, int i) {
    int n = arr.size();
    pre.push_back(i+1);
    for (int j = 0; j < n; j++) {
        if (arr[j] == i+1) {
            dfs(arr, j);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int num, n,key;
    vector<int> ori;
    cin >> n;
    int start = 0;
    unordered_map<int,int> mymap;
    for (int i = 0; i < n; i++) {
        cin >> num;
        if(!mymap.count(num)){
            mymap[num]=1;
        }
        else{
            mymap[num]++;
        }
        if (num == 0) { start = i; }
        ori.push_back(num);
    }
    int max=0;
    int check_num=0;
    int check=0;
    for(const auto & pairs:mymap){
        max=pairs.second>max ?pairs.second : max;
        if(pairs.first!=0){
            if(check_num==0)
            check_num=pairs.second;
            else{
                if(check_num != pairs.second){
                    check=1;
                }
                }
        }
    }
    cout<<max<<" ";
    if(check==1){
        cout<<"no"<<endl;
    }
    else{
        cout<<"yes"<<endl;
    }
    dfs(ori, start);
    for (int i = 0; i < n-1; i++) {
        cout << pre[i] << " ";
    }
    cout<<pre[n-1]<<endl;
    return 0;
}

超时问题已经可以解决,想知道答案错误的是哪个测试点。

相关推荐

  1. L2-3

    2024-04-25 04:58:01       11 阅读
  2. 面试常见知识--

    2024-04-25 04:58:01       33 阅读
  3. 的广度和深度

    2024-04-25 04:58:01       21 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-25 04:58:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-25 04:58:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-25 04:58:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-25 04:58:01       20 阅读

热门阅读

  1. 【Python打包exe文件】

    2024-04-25 04:58:01       22 阅读
  2. Gitea详细介绍

    2024-04-25 04:58:01       34 阅读
  3. 【python】初识爬虫

    2024-04-25 04:58:01       15 阅读
  4. 谈谈如何优雅的使用@Autowired

    2024-04-25 04:58:01       18 阅读
  5. Vue Router,响应式,diff算法

    2024-04-25 04:58:01       45 阅读
  6. tornado模板注入

    2024-04-25 04:58:01       48 阅读
  7. 11.泛型

    11.泛型

    2024-04-25 04:58:01      12 阅读
  8. 基于微信小程序的土地租赁的设计与实现

    2024-04-25 04:58:01       14 阅读
  9. Linux 软件包工具rpmbuild

    2024-04-25 04:58:01       16 阅读
  10. leetcode747-Largest Number At Least Twice of Others

    2024-04-25 04:58:01       12 阅读