
- #include
- 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<
" "; - if(check==1){
- cout<<"no"<
- }
- else{
- cout<<"yes"<
- }
- dfs(ori, start);
- for (int i = 0; i < n-1; i++) {
- cout << pre[i] << " ";
- }
- cout<
-1]<
- return 0;
- }

超时问题已经可以解决,想知道答案错误的是哪个测试点。
-
相关阅读:
LabVIEW中的自动保存功能
Spring 源码(4)在Spring配置文件中自定义标签如何实现?
设置float浮动
获取当前时间为本周的第几小时,getHourOfWeek
[附源码]计算机毕业设计JAVA影院售票系统
【数据结构】原来你叫“带头结点的双向循环链表”啊
特性介绍 | MySQL测试框架 MTR 系列教程(四):语法篇
springboot(ssm学生作业管理系统 在线作业管理平台 Java(code&LW)
【前端精进之路】JS篇:第6期 变量提升和函数提升
unigui点击按钮后弹出悬浮窗,几秒钟后关闭
-
原文地址:https://blog.csdn.net/m0_75015083/article/details/138171447