记录详情

Wrong Answer

/in/foo.cc: In function 'int main()':
/in/foo.cc:23:13: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int temp;
             ^~~~
# 状态 耗时 内存占用
#1 Wrong Answer sh: 1: pause: not found 2ms 324.0 KiB

代码

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main()
{
    int N,Q;
    cin >> N >> Q;
    int num1[N-1];
    int num2[N-1];
    int fruit[N-1];
    int leaf[N+1]={0};
    for (int i=0;i<N-1;i++)
    {
        cin >> num1[i] >> num2[i] >> fruit[i];
        leaf[num1[i]]++;
        leaf[num2[i]]++;
    }
    for (int i=0;i<N-1-Q;i++)
    {
        bool flag=true;
        int temp;
        int tempmin;
        for (int j=0;j<N-1;j++)
        {
            if (num1[j]<0||num2[j]<0)
            continue;
            if (leaf[num1[j]]==1||leaf[num2[j]]==1)
            {
                if (flag)
                {
                    temp=j;
                    tempmin=fruit[j];
                    flag=false;
                    continue;
                }
                if (fruit[j]<tempmin)
                {
                    temp=j;
                    tempmin=fruit[j];
                }
            }
        }
        leaf[num1[temp]]--;
        num1[temp]=-1;
        leaf[num2[temp]]--;
        num2[temp]=-1;
        fruit[temp]=0;

    }
    int output=0;
    for (int i=0;i<N-1;i++)
    output+=fruit[i];
    cout << output;
    system("pause");
    return 0;
}

信息

递交者
类型
自测
题目
二叉苹果树
语言
C++
递交时间
2019-10-22 20:37:17
评测时间
2019-10-22 20:37:17
评测机
分数
0
总耗时
2ms
峰值内存
324.0 KiB