Advertisement
deadwing97

GRAPHTRE Tester

Feb 23rd, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. //teja349
  2. #include <bits/stdc++.h>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <string>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <climits>
  10. #include <utility>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <queue>
  14. #include <stack>
  15. #include <iomanip>
  16. #include <ext/pb_ds/assoc_container.hpp>
  17. #include <ext/pb_ds/tree_policy.hpp>
  18. //setbase - cout << setbase (16); cout << 100 << endl; Prints 64
  19. //setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
  20. //setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
  21. //cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
  22.  
  23. using namespace std;
  24. using namespace __gnu_pbds;
  25.  
  26. #define f(i,a,b) for(i=a;i<b;i++)
  27. #define rep(i,n) f(i,0,n)
  28. #define fd(i,a,b) for(i=a;i>=b;i--)
  29. #define pb push_back
  30. #define mp make_pair
  31. #define vi vector< int >
  32. #define vl vector< ll >
  33. #define ss second
  34. #define ff first
  35. #define ll long long
  36. #define pii pair< int,int >
  37. #define pll pair< ll,ll >
  38. #define sz(a) a.size()
  39. #define inf (1000*1000*1000+5)
  40. #define all(a) a.begin(),a.end()
  41. #define tri pair<int,pii>
  42. #define vii vector<pii>
  43. #define vll vector<pll>
  44. #define viii vector<tri>
  45. #define mod (1000*1000*1000+7)
  46. #define pqueue priority_queue< int >
  47. #define pdqueue priority_queue< int,vi ,greater< int > >
  48. #define flush fflush(stdout)
  49. #define primeDEN 727999983
  50. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  51.  
  52. // find_by_order()  // order_of_key
  53. typedef tree<
  54. int,
  55. null_type,
  56. less<int>,
  57. rb_tree_tag,
  58. tree_order_statistics_node_update>
  59. ordered_set;
  60. #define int ll
  61.  
  62. int dp[5123],cost[5123];
  63. int a[5123],deg[5123];
  64. main(){
  65.     std::ios::sync_with_stdio(false); cin.tie(NULL);
  66.     int t;
  67.     cin>>t;
  68.     while(t--){
  69.         int n,m;
  70.         cin>>n>>m;
  71.         int i;
  72.         vii vec;
  73.         rep(i,n+10){
  74.             deg[i]=0;
  75.             dp[i]=0;
  76.             cost[i]=0;
  77.         }
  78.         rep(i,n){
  79.             cin>>a[i];
  80.             vec.pb(mp(-1*a[i],i));
  81.         }
  82.         int u,v;
  83.         rep(i,m){
  84.             cin>>u>>v;
  85.             u--;
  86.             v--;
  87.             if(a[u]<a[v]){
  88.                 deg[u]++;
  89.             }
  90.             else if(a[u]>a[v]){
  91.                 deg[v]++;
  92.             }
  93.         }
  94.         sort(all(vec));
  95.         dp[1]=1;
  96.         cost[1]=-1*vec[0].ff;
  97.         int j;
  98.         f(j,1,vec.size()){
  99.             u=vec[j].ss;
  100.             fd(i,n,1){
  101.                 cost[i]=cost[i]*deg[u]+cost[i-1]+a[u]*dp[i-1];
  102.                 dp[i]=dp[i-1]+deg[u]*dp[i];
  103.                 cost[i]%=mod;
  104.                 dp[i]%=mod;
  105.             }
  106.         }
  107.         f(i,1,n+1){
  108.             cout<<cost[i]<<" ";
  109.         }
  110.         cout<<endl;
  111.  
  112.     }
  113.     return 0;  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement