Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //teja349
- #include <bits/stdc++.h>
- #include <vector>
- #include <set>
- #include <map>
- #include <string>
- #include <cstdio>
- #include <cstdlib>
- #include <climits>
- #include <utility>
- #include <algorithm>
- #include <cmath>
- #include <queue>
- #include <stack>
- #include <iomanip>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- //setbase - cout << setbase (16); cout << 100 << endl; Prints 64
- //setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
- //setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
- //cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val
- using namespace std;
- using namespace __gnu_pbds;
- #define f(i,a,b) for(i=a;i<b;i++)
- #define rep(i,n) f(i,0,n)
- #define fd(i,a,b) for(i=a;i>=b;i--)
- #define pb push_back
- #define mp make_pair
- #define vi vector< int >
- #define vl vector< ll >
- #define ss second
- #define ff first
- #define ll long long
- #define pii pair< int,int >
- #define pll pair< ll,ll >
- #define sz(a) a.size()
- #define inf (1000*1000*1000+5)
- #define all(a) a.begin(),a.end()
- #define tri pair<int,pii>
- #define vii vector<pii>
- #define vll vector<pll>
- #define viii vector<tri>
- #define mod (1000*1000*1000+7)
- #define pqueue priority_queue< int >
- #define pdqueue priority_queue< int,vi ,greater< int > >
- #define flush fflush(stdout)
- #define primeDEN 727999983
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- // find_by_order() // order_of_key
- typedef tree<
- int,
- null_type,
- less<int>,
- rb_tree_tag,
- tree_order_statistics_node_update>
- ordered_set;
- #define int ll
- int dp[5123],cost[5123];
- int a[5123],deg[5123];
- main(){
- std::ios::sync_with_stdio(false); cin.tie(NULL);
- int t;
- cin>>t;
- while(t--){
- int n,m;
- cin>>n>>m;
- int i;
- vii vec;
- rep(i,n+10){
- deg[i]=0;
- dp[i]=0;
- cost[i]=0;
- }
- rep(i,n){
- cin>>a[i];
- vec.pb(mp(-1*a[i],i));
- }
- int u,v;
- rep(i,m){
- cin>>u>>v;
- u--;
- v--;
- if(a[u]<a[v]){
- deg[u]++;
- }
- else if(a[u]>a[v]){
- deg[v]++;
- }
- }
- sort(all(vec));
- dp[1]=1;
- cost[1]=-1*vec[0].ff;
- int j;
- f(j,1,vec.size()){
- u=vec[j].ss;
- fd(i,n,1){
- cost[i]=cost[i]*deg[u]+cost[i-1]+a[u]*dp[i-1];
- dp[i]=dp[i-1]+deg[u]*dp[i];
- cost[i]%=mod;
- dp[i]%=mod;
- }
- }
- f(i,1,n+1){
- cout<<cost[i]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement