#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 2e5 + 1;
vector < pair <long long,long long> > v[MAXN];
vector < pair <long long,long long> > bufor;
vector < pair <long long,long long> > reakcje;
int main()
{
ios_base::sync_with_stdio(false);
int n,m,k, a;
long long res = 0;
cin>> n >> m >> k;
for(int i = 0; i< n; ++i)
{
cin>>a;
v[i+1].push_back(make_pair(i+1, a));
}
for(int i = 0 ; i< m; ++i)
{
int a,b;
cin>>a>>b;
bufor.push_back(make_pair(a,b));
}
for(int i = 0; i<k; ++i)
{
int a,b;
cin>>a>>b;
reakcje.push_back(make_pair(min(a,b),max(a,b)));
}
//int roz;
for(int i= 0; i<bufor.size(); ++i)
{
for(int j = 0; j < v[bufor[i].first].size(); ++j)
v[bufor[i].second].push_back(v[bufor[i].first][j]);
v[bufor[i].first].clear();
for(int j = 0; j<v[bufor[i].second].size(); ++j)
{
for(int l = j+1; l<v[bufor[i].second].size(); ++l)
{
for(int k = 0; k<reakcje.size(); ++k)
{
//cout<<"lele"<<endl;
//cout<<v[bufor[i].second][j].first<<endl;
//cout<<reakcje[k].first<<endl;
if((v[bufor[i].second][j].first == reakcje[k].first and v[bufor[i].second][l].first == reakcje[k].second) or
(v[bufor[i].second][l].first == reakcje[k].first and v[bufor[i].second][j].first == reakcje[k].second))
{
long long roz = min(v[bufor[i].second][j].second, v[bufor[i].second][l].second);
//cout<<"klops<<"<<endl;
res += 2*roz;
v[bufor[i].second][j].second -= roz;
v[bufor[i].second][l].second -= roz;
}
}
}
}
}
cout<<res<<endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <iostream> #include <vector> using namespace std; const int MAXN = 2e5 + 1; vector < pair <long long,long long> > v[MAXN]; vector < pair <long long,long long> > bufor; vector < pair <long long,long long> > reakcje; int main() { ios_base::sync_with_stdio(false); int n,m,k, a; long long res = 0; cin>> n >> m >> k; for(int i = 0; i< n; ++i) { cin>>a; v[i+1].push_back(make_pair(i+1, a)); } for(int i = 0 ; i< m; ++i) { int a,b; cin>>a>>b; bufor.push_back(make_pair(a,b)); } for(int i = 0; i<k; ++i) { int a,b; cin>>a>>b; reakcje.push_back(make_pair(min(a,b),max(a,b))); } //int roz; for(int i= 0; i<bufor.size(); ++i) { for(int j = 0; j < v[bufor[i].first].size(); ++j) v[bufor[i].second].push_back(v[bufor[i].first][j]); v[bufor[i].first].clear(); for(int j = 0; j<v[bufor[i].second].size(); ++j) { for(int l = j+1; l<v[bufor[i].second].size(); ++l) { for(int k = 0; k<reakcje.size(); ++k) { //cout<<"lele"<<endl; //cout<<v[bufor[i].second][j].first<<endl; //cout<<reakcje[k].first<<endl; if((v[bufor[i].second][j].first == reakcje[k].first and v[bufor[i].second][l].first == reakcje[k].second) or (v[bufor[i].second][l].first == reakcje[k].first and v[bufor[i].second][j].first == reakcje[k].second)) { long long roz = min(v[bufor[i].second][j].second, v[bufor[i].second][l].second); //cout<<"klops<<"<<endl; res += 2*roz; v[bufor[i].second][j].second -= roz; v[bufor[i].second][l].second -= roz; } } } } } cout<<res<<endl; } |
English