#include <stdio.h> #define MAXN 200001 //#define MAXK 500001 //#define MAXN 20 #define MAXK 50 int main() { long n,m,k; long* g =new long[MAXN]; long* a =new long[MAXN]; long* b =new long[MAXN]; long* c =new long[MAXK]; long* d =new long[MAXK]; long res=0; scanf("%ld %ld %ld",&n,&m,&k); for (int i = 1; i <= n; ++i) { scanf("%ld",&g[i]); } for (int i = 1; i <= m; ++i) { scanf("%ld %ld",&a[i], &b[i]); } for (int i = 1; i <= k; ++i) { scanf("%ld %ld",&c[i] ,&d[i]); } for (int j = 1; j <= m; ++j) { for (int i = 1; i <= k; ++i) { if(c[i] == a[j] && d[i] == b[j]) { //printf("if1\n"); if(a[j]>b[j]) { //printf("if11\n"); res=res+2*g[b[j]]; g[b[j]]=g[a[j]]-g[b[j]]; } else { //printf("i12\n"); res=res+2*g[a[j]]; g[b[j]]=g[b[j]]-g[a[j]]; } } else if(d[i] == a[j] && c[i] == b[j]) { //printf("if2\n"); if(a[j]>b[j]) { //printf("if1\n"); res=res+2*g[b[j]]; g[b[j]]=g[a[j]]-g[b[j]]; } else { //printf("if22\n"); res=res+2*g[a[j]]; g[b[j]]=g[b[j]]-g[a[j]]; } } else { //printf("DODAJE\n"); //g[b[j]]=g[b[j]]+g[a[j]]; } //printf(" i:%d j:%d %ld\n",i,j,res ); } } printf("%ld\n",res ); delete[] g; delete[] a; delete[] b; delete[] c; delete[] d; 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 | #include <stdio.h> #define MAXN 200001 //#define MAXK 500001 //#define MAXN 20 #define MAXK 50 int main() { long n,m,k; long* g =new long[MAXN]; long* a =new long[MAXN]; long* b =new long[MAXN]; long* c =new long[MAXK]; long* d =new long[MAXK]; long res=0; scanf("%ld %ld %ld",&n,&m,&k); for (int i = 1; i <= n; ++i) { scanf("%ld",&g[i]); } for (int i = 1; i <= m; ++i) { scanf("%ld %ld",&a[i], &b[i]); } for (int i = 1; i <= k; ++i) { scanf("%ld %ld",&c[i] ,&d[i]); } for (int j = 1; j <= m; ++j) { for (int i = 1; i <= k; ++i) { if(c[i] == a[j] && d[i] == b[j]) { //printf("if1\n"); if(a[j]>b[j]) { //printf("if11\n"); res=res+2*g[b[j]]; g[b[j]]=g[a[j]]-g[b[j]]; } else { //printf("i12\n"); res=res+2*g[a[j]]; g[b[j]]=g[b[j]]-g[a[j]]; } } else if(d[i] == a[j] && c[i] == b[j]) { //printf("if2\n"); if(a[j]>b[j]) { //printf("if1\n"); res=res+2*g[b[j]]; g[b[j]]=g[a[j]]-g[b[j]]; } else { //printf("if22\n"); res=res+2*g[a[j]]; g[b[j]]=g[b[j]]-g[a[j]]; } } else { //printf("DODAJE\n"); //g[b[j]]=g[b[j]]+g[a[j]]; } //printf(" i:%d j:%d %ld\n",i,j,res ); } } printf("%ld\n",res ); delete[] g; delete[] a; delete[] b; delete[] c; delete[] d; return 0; } |