QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747118 | #9623. 合成大西瓜 | yeah14 | WA | 3ms | 40448kb | C++17 | 3.4kb | 2024-11-14 16:23:02 | 2024-11-14 16:23:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII pair<int ,int>
const int INF = 0x3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int fp(int a, int x, int mod) {
int ans = 1;
while (x) {
if (x & 1)ans *= a;
ans %= mod;
a *= a;
a %= mod;
x >>= 1;
}
return ans;
}
//const int N = 1e6;
struct edge {
int u, v;
};
struct node {
int w;
int id;
bool operator<(const node& a)const {
if (w != a.w)
return w > a.w;
else return id > a.id;
}
};
int degree[N];
node a[N];
//vector<edge>e[N];
priority_queue<node>q;
priority_queue<node>e[N];
node st[N];
int top = 0;
int cnt = 0;
bool vis[N];
void solve() {
int n, m;
cin >> n >> m;
int k = n;
int cnt = n;
for (int i = 1; i <= n; i++) {
cin >> a[i].w;
vis[i] = 1;
a[i].id = i;
}
for (int i = 1; i <= n; i++) {
q.push(a[i]);
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
/* e[u].push_back({ u,v });
e[v].push_back({ v,u });*/
e[u].push(a[v]);
e[v].push(a[u]);
degree[v]++;
degree[u]++;
}
while (cnt >1) {
while ((vis[q.top().id]==0||degree[q.top().id] < 2)&&!q.empty()) {
q.pop();
if (q.empty())break;
}
if (q.empty())break;
node u = q.top();
q.pop();
node q1 = e[u.id].top();
e[u.id].pop();
while (vis[q1.id] == 0) {
q1 = e[u.id].top();
e[u.id].pop();
}
node q2 = e[u.id].top();
e[u.id].pop();
while (vis[q2.id] == 0) {
q2 = e[u.id].top();
e[u.id].pop();
}
cnt -= 2;
k++;
a[k].w = max(min(q1.w, q2.w), u.w);
a[k].id = k;
map<int, bool>vv;
vis[q1.id] = 0;
vis[q2.id] = 0;
vis[u.id] = 0;
vis[k] = 1;
while (!e[q1.id].empty()) {
node p = e[q1.id].top();
e[q1.id].pop();
degree[p.id]--;
if (vis[p.id] == 0)continue;
degree[p.id]++;
degree[k]++;
e[p.id].push(a[k]);
e[k].push(a[p.id]);
vv[p.id]=1;
}
while (!e[q2.id].empty()) {
node p = e[q2.id].top();
e[q2.id].pop();
degree[p.id]--;
if (vis[p.id] == 0)continue;
if (vv.count(p.id) != 0)continue;
degree[k]++;
degree[p.id]++;
e[p.id].push(a[k]);
e[k].push(a[p.id]);
vv[p.id] = 1;
}
while (!e[u.id].empty()) {
node p = e[u.id].top();
e[u.id].pop();
degree[p.id]--;
if (vis[p.id] == 0)continue;
if (vv.count(p.id) != 0)continue;
degree[k]++;
degree[p.id]++;
e[p.id].push(a[k]);
e[k].push(a[p.id]);
vv[p.id] = 1;
}
q.push(a[k]);
}
cout << a[k].w << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
/*
7 7
1 1 2 3 1 2 1
1 2
2 3
1 3
2 4
2 5
5 6
5 7
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 38348kb
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
Wrong Answer
time: 0ms
memory: 40448kb
input:
5 7 1 5 3 1 4 3 5 1 3 5 1 1 4 5 4 2 4 3 2
output:
4
result:
wrong answer 1st lines differ - expected: '5', found: '4'