QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750342#9623. 合成大西瓜lqh2024#WA 0ms3788kbC++201.4kb2024-11-15 14:11:212024-11-15 14:11:22

Judging History

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

  • [2024-11-15 14:11:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2024-11-15 14:11:21]
  • 提交

answer

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

void QAQ() {
    int n, m;
    cin >> n >> m;

    vector<int> a(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector adj(n + 1, set<int>());

    for (int i = 1, u, v; i <= m; i++) {
        cin >> u >> v;
        adj[u].emplace(v), adj[v].emplace(u);
    }

    vector<int> dp(n + 1);
    int ans = 0;

    for (int i = 1; i <= n; i++) {
        if (adj[i].size() != 1) {
            ans = max(ans, a[i]);
        } else {
            dp[i] = a[i];
        }
    }

    vector<int> vis(n + 1);

    auto dfs = [&](auto && self, int u, int fa = 0) -> void {
        multiset<int, greater<>> s;
        vis[u] = 1;
        for (auto & v : adj[u]) if (v != fa && !vis[v]) {
            self(self, v, u);
            if (dp[v]) {
                s.insert(dp[v]);
            }
        }
        if (s.size() >= 3) {
            ans = max(ans, *next(s.begin()));
        } else if (s.size() >= 2) {
            dp[u] = *next(s.begin());
        } else {
            
        }
    };

    for (int i = 1; i <= n; i++) {
        if (adj[i].size() >= 2) {
            dfs(dfs, i);
            break;
        }
    }

    cout << ans << "\n";
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    // cin >> t;
    for(cout << fixed << setprecision(12); t--; QAQ());
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

5 7
1 5 3 1 4
3 5
1 3
5 1
1 4
5 4
2 4
3 2

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

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

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

3 2
2 2 2
2 3
1 3

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

5 5
3 1 2 4 5
3 2
2 4
3 5
5 1
2 5

output:

5

result:

ok single line: '5'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

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

output:

7

result:

ok single line: '7'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3620kb

input:

3 2
1 2 3
3 1
2 1

output:

1

result:

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