Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4786)
- #pragma warning(disable:4996)
- #include<list>
- #include<bitset>
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<vector>
- #include<set>
- #include<map>
- #include<functional>
- #include<string>
- #include<cstring>
- #include<cstdlib>
- #include<queue>
- #include<utility>
- #include<fstream>
- #include<sstream>
- #include<cmath>
- #include<stack>
- #include<assert.h>
- using namespace std;
- #define MEM(a, b) memset(a, (b), sizeof(a))
- #define CLR(a) memset(a, 0, sizeof(a))
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
- #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
- #define S(X) ( (X) * (X) )
- #define SZ(V) (int )V.size()
- #define FORN(i, n) for(i = 0; i < n; i++)
- #define FORAB(i, a, b) for(i = a; i <= b; i++)
- #define ALL(V) V.begin(), V.end()
- #define IN(A, B, C) ((B) <= (A) && (A) <= (C))
- typedef pair<int,int> PII;
- typedef pair<double, double> PDD;
- typedef vector<int> VI;
- typedef vector<PII > VP;
- #define AIN(A, B, C) assert(IN(A, B, C))
- //typedef int LL;
- typedef long long int LL;
- //typedef __int64 LL;
- const LL mod = 1000000007;
- LL bigmod(LL a, LL b) {
- if (b == 0) return 1;
- LL x = bigmod(a, b / 2);
- x = (x * x) % mod;
- if (b & 1) x = (x * a) % mod;
- return x;
- }
- int n, m, k;
- LL v[100005];
- int s[100005];
- VI V[100005];
- int mark[100005], vis[100005];
- void flood() {
- for (int i = 1; i <= n; i++) {
- if (!mark[i]) continue;
- for (int v : V[i]) {
- vis[v] = 1;
- }
- }
- }
- VI G[100005];
- int cnt[100005];
- LL p2[100005];
- int main()
- {
- scanf("%d %d %d", &n, &m, &k);
- for (int i = 1; i <= n; i++) scanf("%lld", &v[i]);
- for (int i = 1; i <= k; i++) scanf("%d", &s[i]);
- for (int i = 1; i <= m; i++) {
- int u, v;
- scanf("%d %d", &u, &v);
- V[u].push_back(v);
- V[v].push_back(u);
- }
- for (int i = 1; i <= k; i++) {
- mark[s[i]] = 1;
- }
- flood();
- for (int i = 1; i <= n; i++) {
- if (vis[i] && v[i] && !mark[i]) {
- printf("-1\n");
- return 0;
- }
- }
- for (int i = 1; i <= k; i++) {
- int u = s[i];
- for (int v : V[u]) {
- G[v].push_back(cnt[v]);
- }
- cnt[u]++;
- }
- p2[0] = 1;
- for (int i = 1; i <= MAX(n, k); i++) {
- p2[i] = (p2[i - 1] * 2) % mod;
- }
- LL ans = 0;
- for (int i = 1; i <= n; i++) {
- LL now = 0;
- for (int x : G[i]) {
- now = (now + p2[cnt[i] - x]);
- }
- now %= mod;
- now = (now * v[i]) % mod;
- now = (now * bigmod(p2[cnt[i]] + mod - 1, mod - 2)) % mod;
- ans += now;
- }
- ans %= mod;
- printf("%lld\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement