QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750033#9623. 合成大西瓜SnowballWA 1ms5944kbC++141.2kb2024-11-15 12:15:552024-11-15 12:15:55

Judging History

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

  • [2024-11-15 12:15:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5944kb
  • [2024-11-15 12:15:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

// clang-format off
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') f = -f; ch = getchar();}
    while(isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
// clang-format on

const int N = 100005;
vector<int> edges[N];
int w[N];

int main()
{
    int n = read(), m = read();
    for (int i = 1; i <= n; i++)
        w[i] = read();
    for (int i = 1; i <= m; i++)
    {
        int u = read(), v = read();
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    vector<int> leaves, other;
    for (int i = 1; i <= n; i++)
    {
        if (edges[i].size() == 1)
            leaves.push_back(w[i]);
        else
            other.push_back(w[i]);
    }
    sort(all(leaves), greater<int>());
    sort(all(other), greater<int>());

    if (leaves.size() <= 1)
    {
        if (!other.empty())
            cout << other[0];
        else
            cout << leaves[0]; // 当没有非叶子节点时,输出唯一的叶子节点
    }
    else
        cout << leaves[1];

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5944kb

input:

7 9
1 4 1 3 3 6 7
5 4
3 6
3 4
2 3
5 2
2 6
6 7
5 1
4 6

output:

1

result:

wrong answer 1st lines differ - expected: '6', found: '1'