Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cmath>
  6. #include <stack>
  7. #include <iomanip>
  8. #include <bitset>
  9.  
  10. #define szybcior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  11.  
  12. using namespace std;
  13. typedef long long ll;
  14. typedef long double ld;
  15. const ll inf = 10e17;
  16. const ll M = 1000000007;
  17. const ll ile = 100008;
  18. ll n,m;
  19. ll koszt[ile];
  20. ll post[ile];
  21. vector<ll> v[ile];
  22. vector<ll> v1[ile];
  23. bitset<ile> bo;
  24. bitset<ile> bo1;
  25. ll czas = 0;
  26. pair<ll,ll> ans = {0,1}; // koszst | ilosc mozliwosci
  27.  
  28.  
  29. void dfs(ll start)
  30. {
  31.       bo[start] = true;
  32.       // cout << "wierzcholek " << start << "\n";
  33.       for(auto it: v[start])
  34.             if(!bo[it])
  35.                   dfs(it);
  36.  
  37.       post[++czas] = start;
  38. }
  39.  
  40. // ll dfs1(ll start)
  41. // {
  42. //       bo1[start] = true;
  43. //       ll wartosc = koszt[start];
  44. //       // cout << "wierzcholek " << start << "\n";
  45. //       for(auto it: v1[start])
  46. //             if(!bo1[it])
  47. //             {
  48. //                   ll pomoc = dfs1(it);
  49. //                   if(pomoc == wartosc) ilosc++;
  50. //                   else if(pomoc < wartosc)
  51. //                   {
  52. //                         cout << "ZMIEJSZANIE " << wartosc << " na " << pomoc << " ";
  53. //                         ilosc = 1;
  54. //                         wartosc = pomoc;
  55. //                   }
  56. //                   ilosc %= M;
  57. //             }
  58.  
  59. //       cout << start << ": " << ilosc << " wartosc: " << wartosc << "\n";
  60. //       return wartosc;
  61. // }
  62.  
  63. void dfs1(ll v, ll& cand, ll& cnt) {
  64.       bo1[v] = true;
  65.       if(koszt[v] ==cand)
  66.             cnt++;
  67.       if(koszt[v] < cand)
  68.             cand=koszt[v], cnt=1;
  69.       for(auto && it: v1[v])
  70.             if(!bo1[it])
  71.                   dfs1(it, cand, cnt);
  72. }
  73. int main()
  74. {
  75.       szybcior;
  76.       cin >> n;
  77.       for(int i = 1; i <= n; i++)
  78.             cin >> koszt[i];
  79.      
  80.       cin >> m;
  81.       for(int i = 0; i < m; i++)
  82.       {
  83.             ll a,b;
  84.             cin >> a >> b;
  85.             v[a].push_back(b);
  86.             v1[b].push_back(a);
  87.       }
  88.      
  89.       for(int i = 1; i <= n; i++)
  90.             if(!bo[i])
  91.                   dfs(i); // ustawienie post orderu
  92.  
  93.  
  94.       // for(int i = 1; i <= n; i++)   cout << i << ": " << post[i] << "\n";      
  95.       for(int i = n; i > 0; i--)
  96.       {
  97.             // cout << 'x';
  98.             if(!bo1[post[i]])
  99.             {
  100.                   ll ile =-1, mini = inf ;
  101.                   dfs1(post[i], mini, ile);
  102.                   // cout << mini << " " << ile << "\n";
  103.                   ans.first +=  mini;
  104.                   ans.second = ans.second*mini%M;
  105.                   ans.second %= M;
  106.             }
  107.            
  108.       }
  109.       cout << ans.first << " " << ans.second << " ";
  110.       return 0;
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement