Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8.
You can try to decode it yourself by downloading it here.
#include <stdio.h> #include <time.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <map> #include <string> #include <vector> #include <iostream> #include <sstream> #include <queue> #include <algorithm> using namespace std; #define ll long long #define PB push_back #define FOR(a,start,end) for(ll a=ll(start); a<ll(end); a++) #define INF INT_MAX #define SORT(a) sort(a.begin(),a.end()) #define CL(a,x) memset(a,x,sizeof(a)) #define REP(a,x) for(ll a=0;a<x;a++) #define REP1(a,x) for(ll a=1;a<=x;a++) #define MP make_pair typedef vector<ll> vi; typedef pair<ll,ll> pii; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vector<ll> > vvi; typedef vector<vector<string> > vvs; typedef vector<pair<string,string> > vss; typedef pair<string,string> pss; typedef pair<ll,pii> ppii; typedef vector<ppii> vppii; typedef vector<vector<pii> > vvii; typedef vector<vvi> vvvi; ppii px; vppii vc; int i0,i,j,k,n,k1,k2,m; ll z,c,d,t; ll a,b; vi vk,vg,vig; vii vp,vd,vu,vp1; vvi vvk,vvf,vvk0; pii p1,p2,p0; ll ta[100010]; int czy (int i0,vi vk0){ int i; for(i=0;i<vk0.size();i++) if(vk0[i]==i0) return 1; return 0; } vii para(int ix,int i0,int a0,int b0){ pii p0,p1; int i,j,i01,i02,r; vii vp0; p0=MP(ix,i0); r=0; for(int i1=vig[i0];i1<vvk[i0].size();i1++){ //if(vvk0[i0][i1]==0){ if(vvk[i0][i1]==ix) break; if(vg[vvk[i0][i1]]>0){ //vvk0[i0][i1]=1; i01=vvk[i0][i1]; // if(i01==ix) // break; if(czy(i01,vvf[b0])){ if(i1==vig[i0]) vig[i0]++; vp0=para(i0,i01,b0,a0); break; } } } vp0.push_back(p0); return vp0; } vii lr(pii p1){ //p1 - para fiolek int i,j,i0,i02; vii vp1,vp0; pii p0; vp1.clear(); for(i=0;i<vvf[p1.first].size();i++){ for(int i1=vig[vvf[p1.first][i]];i1<vvk[vvf[p1.first][i]].size();i1++){ i0=vvk[vvf[p1.first][i]][i1]; //if(vvk0[vvf[p1.first][i]][i1]==0){ if(vg[i0]>0){ if(czy(i0,vvf[p1.second])){ //czy jest w p1.second if(i1==vig[vvf[p1.first][i]]) vig[vvf[p1.first][i]]++; vp0=para(vvf[p1.first][i],i0,p1.second,p1.first); //zwraca par� for(int i2=0;i2<vp0.size();i2++) vp1.push_back(vp0[i2]); //break; //s� woelokrotne pary! } // vvk0[vvf[p1.first][i]][i1]=1; } } } return vp1; } int main() { //freopen( "c:\\wojtek\\uva\\pa\\debug\\t3.in", "rt", stdin); // ll czas=clock(); //pi=2*acos(0.0); //scanf("%ld",&t); cin>>n>>m>>k; vg.clear(); vig.assign(n,0); for(i=0;i<n;i++){ cin>>a; vg.push_back(a); } vp.clear(); for(i=0;i<m;i++){ cin>>a>>b; vp.push_back(MP(a-1,b-1)); } vk.clear(); vvk.assign(n,vk); vvk0.assign(n,vk); vvf.assign(n,vk); for(i=0;i<k;i++){ cin>>a>>b; vvk[a-1].push_back(b-1); vvk[b-1].push_back(a-1); vvk0[a-1].push_back(0); vvk0[b-1].push_back(0); } z=0; for(i=0;i<n;i++) vvf[i].push_back(i); for(i=0;i<m;i++){ vp1=lr(vp[i]); for(j=0;j<vp1.size();j++){ a=min(vg[vp1[j].first],vg[vp1[j].second]); z+=2*a; vg[vp1[j].first]-=a; vg[vp1[j].second]-=a; } vk.clear(); for(j=0;j<vvf[vp[i].first].size();j++){ if(vg[vvf[vp[i].first][j]]>0) vk.push_back(vvf[vp[i].first][j]); } for(j=0;j<vvf[vp[i].second].size();j++){ if(vg[vvf[vp[i].second][j]]>0) vk.push_back(vvf[vp[i].second][j]); } swap(vvf[vp[i].second],vk); } cout<<z<<endl; //czas = clock() - czas; //printf("%lf\n",double(czas)/CLOCKS_PER_SEC); return 0; }
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #include <stdio.h> #include <time.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <map> #include <string> #include <vector> #include <iostream> #include <sstream> #include <queue> #include <algorithm> using namespace std; #define ll long long #define PB push_back #define FOR(a,start,end) for(ll a=ll(start); a<ll(end); a++) #define INF INT_MAX #define SORT(a) sort(a.begin(),a.end()) #define CL(a,x) memset(a,x,sizeof(a)) #define REP(a,x) for(ll a=0;a<x;a++) #define REP1(a,x) for(ll a=1;a<=x;a++) #define MP make_pair typedef vector<ll> vi; typedef pair<ll,ll> pii; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vector<ll> > vvi; typedef vector<vector<string> > vvs; typedef vector<pair<string,string> > vss; typedef pair<string,string> pss; typedef pair<ll,pii> ppii; typedef vector<ppii> vppii; typedef vector<vector<pii> > vvii; typedef vector<vvi> vvvi; ppii px; vppii vc; int i0,i,j,k,n,k1,k2,m; ll z,c,d,t; ll a,b; vi vk,vg,vig; vii vp,vd,vu,vp1; vvi vvk,vvf,vvk0; pii p1,p2,p0; ll ta[100010]; int czy (int i0,vi vk0){ int i; for(i=0;i<vk0.size();i++) if(vk0[i]==i0) return 1; return 0; } vii para(int ix,int i0,int a0,int b0){ pii p0,p1; int i,j,i01,i02,r; vii vp0; p0=MP(ix,i0); r=0; for(int i1=vig[i0];i1<vvk[i0].size();i1++){ //if(vvk0[i0][i1]==0){ if(vvk[i0][i1]==ix) break; if(vg[vvk[i0][i1]]>0){ //vvk0[i0][i1]=1; i01=vvk[i0][i1]; // if(i01==ix) // break; if(czy(i01,vvf[b0])){ if(i1==vig[i0]) vig[i0]++; vp0=para(i0,i01,b0,a0); break; } } } vp0.push_back(p0); return vp0; } vii lr(pii p1){ //p1 - para fiolek int i,j,i0,i02; vii vp1,vp0; pii p0; vp1.clear(); for(i=0;i<vvf[p1.first].size();i++){ for(int i1=vig[vvf[p1.first][i]];i1<vvk[vvf[p1.first][i]].size();i1++){ i0=vvk[vvf[p1.first][i]][i1]; //if(vvk0[vvf[p1.first][i]][i1]==0){ if(vg[i0]>0){ if(czy(i0,vvf[p1.second])){ //czy jest w p1.second if(i1==vig[vvf[p1.first][i]]) vig[vvf[p1.first][i]]++; vp0=para(vvf[p1.first][i],i0,p1.second,p1.first); //zwraca par� for(int i2=0;i2<vp0.size();i2++) vp1.push_back(vp0[i2]); //break; //s� woelokrotne pary! } // vvk0[vvf[p1.first][i]][i1]=1; } } } return vp1; } int main() { //freopen( "c:\\wojtek\\uva\\pa\\debug\\t3.in", "rt", stdin); // ll czas=clock(); //pi=2*acos(0.0); //scanf("%ld",&t); cin>>n>>m>>k; vg.clear(); vig.assign(n,0); for(i=0;i<n;i++){ cin>>a; vg.push_back(a); } vp.clear(); for(i=0;i<m;i++){ cin>>a>>b; vp.push_back(MP(a-1,b-1)); } vk.clear(); vvk.assign(n,vk); vvk0.assign(n,vk); vvf.assign(n,vk); for(i=0;i<k;i++){ cin>>a>>b; vvk[a-1].push_back(b-1); vvk[b-1].push_back(a-1); vvk0[a-1].push_back(0); vvk0[b-1].push_back(0); } z=0; for(i=0;i<n;i++) vvf[i].push_back(i); for(i=0;i<m;i++){ vp1=lr(vp[i]); for(j=0;j<vp1.size();j++){ a=min(vg[vp1[j].first],vg[vp1[j].second]); z+=2*a; vg[vp1[j].first]-=a; vg[vp1[j].second]-=a; } vk.clear(); for(j=0;j<vvf[vp[i].first].size();j++){ if(vg[vvf[vp[i].first][j]]>0) vk.push_back(vvf[vp[i].first][j]); } for(j=0;j<vvf[vp[i].second].size();j++){ if(vg[vvf[vp[i].second][j]]>0) vk.push_back(vvf[vp[i].second][j]); } swap(vvf[vp[i].second],vk); } cout<<z<<endl; //czas = clock() - czas; //printf("%lf\n",double(czas)/CLOCKS_PER_SEC); return 0; } |