#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
void solve(){
int n , m , qu;
cin >> n >> m >> qu;
ll arr[n + 1];
for(int i = 1; i <= n; i++)cin >> arr[i];
vector<int> adj[n + 1];
for(int i = 0; i < m; i++){
int a , b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
bool vis[n + 1];
for(int i = 0; i < qu; i++){
int u , v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
queue<int> q;
memset(vis,0,sizeof vis);
vector<ll> f;
for(int j = 1; j <= n; j++){
if(!vis[j]){
q.push(j);
vis[j] = 1;
ll sum = arr[j];
while(q.size()){
int node = q.front();
q.pop();
for(int k : adj[node]){
if(!vis[k]){
vis[k] = 1;
sum += arr[k];
q.push(k);
}
}
}
f.pb(sum);
}
}
adj[u].pop_back();
adj[v].pop_back();
sv(f);
reverse(all(f));
ll ans = 0;
for(ll j = 0; j < (int)f.size(); j++){
ans += (j + 1LL) * f[j];
}
cout << ans << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |