QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737062#9623. 合成大西瓜josoWA 0ms14540kbC++141.0kb2024-11-12 14:29:492024-11-12 14:29:53

Judging History

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

  • [2024-11-12 14:29:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14540kb
  • [2024-11-12 14:29:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=4e5+10;
typedef pair<int,int>PII;
vector<int>e[N];
int a[N];
bool st[N];
vector<int>edge;
void dfs(int u){
    st[u]=1;
    for(int v:e[u]){
        if(st[v]) continue;
        dfs(v);
    }
    if(e[u].size()==1) edge.push_back(a[u]);
}
void solve(){
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n==1){
        cout<<a[1]<<endl;
        return;
    }
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int ans=0;
    dfs(1);
    sort(edge.begin(),edge.end(),less<int>());
    for(int i=1;i<=n;i++){
        if(e[i].size()>=2){
            ans=max(ans,a[i]);
        }
    }
     if(edge.size()>=2){
        ans=max(ans,edge[1]);
    }
    cout<<ans<<endl;

}
signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 14540kb

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:

7

result:

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