QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#758826 | #9623. 合成大西瓜 | 5720226849# | WA | 1ms | 9856kb | C++14 | 2.9kb | 2024-11-17 19:56:54 | 2024-11-17 19:56:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ls u << 1
#define rs u << 1 | 1
#define all(x) x.begin(),x.end()
#define i128 __int128
#define int long long
#define Genshin_Impact return
#define Starts 0
#define _o_o_ return
#define o_o_o return
inline int gcd(int a, int b) {return b > 0 ? gcd(b, a % b) : a;}
inline int lowbit(int x) {return x & (-x);}
int qmi(int a, int b, int mod){int res = 1;while(b) {if(b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}
// inline i128 read(){i128 x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
// inline void print(i128 x){if(x < 0){putchar('-');x = -x;}if(x > 9)print(x / 10);putchar(x % 10 + '0');}
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, PII> PIII;
const int N = 5e5 + 10, logn = 21, inf = 1e18, mod = 998244353, M = 2e6 + 10;
const int P = 131;
#define ull unsigned long long
int n, m;
vector<int>v;
int a[N], b[N], d[N], mx = 0;
PII p[N];
void solve()
{
// 选一个不是叶子的最大值
// 或者次大叶子
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> a[i], b[i] = a[i];
for(int i = 1; i <= m; i ++) {
int u, v; cin >> u >> v;
d[u] ++, d[v] ++;
p[i] = {u, v};
}
if(n == 1) {
cout << a[1] << '\n';
return;
}
// 对于一条边上的两个点,度大于2就可以每个点都做最后的点,否则就是次大
sort(b + 1, b + n + 1);
int mx = 0;
for(int i = 1; i <= m; i ++)
if(d[p[i].x] == 1) {
mx = max(mx, a[p[i].y]);
// 或者除去这个值的次大值
if(a[p[i].y] == b[n - 2]) {
if(a[p[i].x] >= b[n - 1])
mx = max(mx, b[n - 1]);
else mx = max(mx, a[p[i].x]);
}
else {
if(a[p[i].x] >= b[n - 1]) mx = max(mx, b[n - 2]);
else mx = max(mx, a[p[i].x]);
}
}
else if(d[p[i].y] == 1) {
mx = max(mx, a[p[i].x]);
if(a[p[i].x] == b[n - 2]) {
if(a[p[i].y] >= b[n - 1])
mx = max(mx, b[n - 1]);
else mx = max(mx, a[p[i].y]);
}
else {
if(a[p[i].y] >= b[n - 1]) mx = max(mx, b[n - 2]);
else mx = max(mx, a[p[i].y]);
}
}
else mx = max(mx, max(a[p[i].x], a[p[i].y]));
cout << mx << '\n';
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
Genshin_Impact Starts;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9680kb
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: 9816kb
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: 9856kb
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: 1ms
memory: 9656kb
input:
3 2 2 2 2 2 3 1 3
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 1ms
memory: 9812kb
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: 1ms
memory: 9812kb
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: 1ms
memory: 9804kb
input:
3 2 1 2 3 3 1 2 1
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 1ms
memory: 9680kb
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: 1ms
memory: 9800kb
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: 1ms
memory: 9856kb
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: 1ms
memory: 9732kb
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: 1ms
memory: 9716kb
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:
15
result:
wrong answer 1st lines differ - expected: '16', found: '15'