QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#837300 | #9623. 合成大西瓜 | jiangzhihui# | RE | 1ms | 7124kb | C++14 | 1.2kb | 2024-12-29 21:48:14 | 2024-12-29 21:48:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn],d[maxn],head[maxn],mpt[maxn],cnt=1,ans=1;
vector<int> g[maxn];
priority_queue<int> que;
bool cmp(int x,int y){
return a[x]>a[y];
}
int main(){
// freopen("1.in","r",stdin);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
d[u]++;
d[v]++;
}
if(n==1||m==0){
cout<<a[1]<<endl;
return 0;
}
for(int i=1;i<=n;i++){
if(d[i]>1){
ans=max(ans,a[i]);
// sort(g[i].begin(),g[i].end(),cmp);
int mx1=max(a[g[i][0]],a[g[i][1]]),mx2=min(a[g[i][0]],a[g[i][1]]);
for(int j=2;j<g[i].size();j++){
int v=a[g[i][j]];
if(v>=mx1){
mx2=mx1;
mx1=v;
}else if(v>=mx2){
mx2=v;
}
}
ans=max(ans,mx2);
}else{
que.push(a[i]);
}
}
que.pop();
if(!que.empty())ans=max(ans,que.top());
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7124kb
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: -100
Runtime Error
input:
5 7 1 5 3 1 4 3 5 1 3 5 1 1 4 5 4 2 4 3 2