QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#779193 | #9623. 合成大西瓜 | victoryAC# | WA | 4ms | 20212kb | C++17 | 3.0kb | 2024-11-24 17:53:35 | 2024-11-24 17:53:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pos string::npos
#define endl '\n'
#define inf 1e18
typedef unsigned long long ull;
const int mod = 1e9+7;
const int N = 5e5+10;
const int Maxn = 2e5+5;
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int Inv[N],F[N];//组合数C2
int gcd(int a,int b){ return b == 0 ? a : gcd(b,a%b);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}
int km(int a,int b,int mod)
{int ans=1;while(b){if(b&1) ans=ans*a%mod;b>>=1;a=a*a%mod;}return ans;}
int km1(int a,int b,int mod)//指数取模,2^2^i,单求2^i要取模MOD-1
{int ans=1;mod--;while(b){if(b&1) ans=ans*a%mod;b>>=1;a=a*a%mod;}return ans;}
int C(int a,int b,int p){if(b>a) return 0;int res=1;for(int i=b,j=a;i>=1;i--,j--){res=res*j%p;res=res*km(i,p-2,p)%p;}return res;}
int Lucas(int a,int b,int p){if(a<p&&b<p) return C(a,b,p);return C(a%p,b%p,p)*Lucas(a/p,b/p,p)%p;}
int C2(int a,int b,int p){return F[a]*Inv[a-b]%p*Inv[b]%p;}
void C2init(int n,int p){n--;F[0]=F[1]=1;for(int i=2;i<=n;i++)F[i]=F[i-1]*i%p;Inv[n]=km(F[n],p-2,p);for(int i=n-1;i>=0;i--)Inv[i]=Inv[i+1]*(i+1)%p;}
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
int n,m,k,q,a[N],din[N];
vector<int> h[N];
void solve()
{
int mi=1e9,mi1=0;
bool ok=0;
vector<int> ve;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
mi=min(mi,a[i]);
//ve.push_back(a[i]);
}
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
din[u]++,din[v]++;
h[u].push_back(v);
h[v].push_back(u);
}
if(n==1){
cout<<a[1]<<endl;
return ;
}
int ans=mi;
//vector<int> x;
for(int i=1;i<=n;i++){
if(din[i]>1) {
ans=max(ans,a[i]);
}
}
for(int i=1;i<=n;i++){
int mx=0,mx1=0,cnt=0;
if(din[i]==1) continue;
vector<int> tt;
for(auto v:h[i]){
if(din[v]!=1||a[v]<=a[i]) continue;
//tt.push_back(a[v]);
cnt++;
if(mx==0) mx=max(mx,a[v]);
else {
if(a[v]>mx) mx1=mx,mx=a[v];
else mx1=max(mx1,a[v]);
}
}
//sort(tt.begin(),tt.end());
if(cnt>=2) {
// ans=max(ans,tt[tt.size()-2]);
ans=max(ans,mx1);
}
}
//sort(ve.begin(),ve.end());
// if(ve[0]==ve[1]) ok=1;
// else mi1=ve[1];
// int ans=0;
// for(auto tt:x){
// if(a[tt]==ve[0]){
// if(ok) ans=max(ans,max(a[tt],mi));
// else ans=max(ans,max(a[tt],mi1));
// }
// else{
// ans=max(ans,max(a[tt],mi));
// }
// }
cout<<ans<<endl;
}
// 7 7
// 1 1 2 3 1 2 1
// 1 2
// 2 3
// 1 3
// 2 4
// 2 5
// 5 6
// 5 7
signed main()
{
ios;
int T=1;
//C2init(N,mod);
//cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 20212kb
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: 4ms
memory: 15288kb
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: 2ms
memory: 15372kb
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: 15416kb
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: 15356kb
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: 15300kb
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: 0
Accepted
time: 2ms
memory: 15372kb
input:
3 2 1 2 3 3 1 2 1
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 0ms
memory: 15344kb
input:
9 9 6 1 1 1 3 7 1 8 9 9 8 6 7 2 7 5 6 7 9 5 1 7 3 1 6 1 4
output:
9
result:
ok single line: '9'
Test #9:
score: 0
Accepted
time: 0ms
memory: 15300kb
input:
9 10 7 7 4 2 2 6 6 8 9 9 6 4 6 1 2 4 3 5 6 7 5 6 8 7 4 1 7 1 9
output:
9
result:
ok single line: '9'
Test #10:
score: 0
Accepted
time: 0ms
memory: 15300kb
input:
5 6 3 2 1 1 2 3 5 2 4 3 1 2 3 4 1 1 5
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 0ms
memory: 15284kb
input:
7 7 4 4 5 1 1 6 7 2 1 1 7 5 4 2 4 1 3 5 6 7 4
output:
7
result:
ok single line: '7'
Test #12:
score: -100
Wrong Answer
time: 3ms
memory: 19476kb
input:
17 17 2 15 7 13 8 6 12 8 10 13 15 5 7 8 13 16 17 5 9 6 1 7 9 6 10 16 15 3 6 14 3 11 6 12 15 8 4 9 10 7 6 15 6 2 10 8 10 13 6 17 7
output:
13
result:
wrong answer 1st lines differ - expected: '16', found: '13'