이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll=long long;
vector<int> adj[200005];
int a[200005];
struct A{
int u,v;
A(int u=0,int v=0):u(u),v(v){}
bool operator<(const A &o)const{
if(a[u]!=a[o.u]) return a[u]>a[o.u];
return a[v]>a[o.u];
}
};
priority_queue<A> pq;
ll dp[200005];
bitset<200005> vis;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n,m,Q; cin>>n>>m>>Q;
int mx=1;
for(int i=1;i<=n;++i){
cin>>a[i];
if(a[i]>a[mx]) mx=i;
dp[i]=1e18;
}
for(int i=0;i<m;++i){
int u,v; cin>>u>>v;
adj[u].eb(v), adj[v].eb(u);
}
for(auto &v:adj[mx]){
dp[v]=a[mx];
pq.emplace(mx,v);
}
dp[mx]=0;
vis[mx]=1;
while(pq.size()){
auto [p,u]=pq.top(); pq.pop();
if(dp[u]!=a[p]) continue;
vis[u]=1;
for(auto &v:adj[u]){
if(dp[v]<=a[u]||vis[v]) continue;
dp[v]=a[u];
pq.emplace(u,v);
}
}
ll ans=0;
for(int i=1;i<=n;++i) ans+=dp[i];
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |