fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<stdio.h>
  4. #include<set>
  5. #include<queue>
  6. #include<vector>
  7. #include<cmath>
  8. #include<map>
  9.  
  10. using namespace std;
  11.  
  12. const int maxi=2*(1e6+10);
  13.  
  14. priority_queue <pair<long long ,int>> pq[maxi];
  15. vector <int> g[maxi],ds[maxi];
  16. set <long long> st[maxi];
  17. vector <pair<int,int>> mp[maxi];
  18. map <pair<int,int>, int> c,ob;
  19. long long ans[maxi];
  20. int gr[maxi];
  21. pair<long long , pair<int,int>> v[maxi];
  22. int x,y,n,m,q;
  23. long long z;
  24. long long b[maxi],cnt[maxi];
  25.  
  26.  
  27. void spoj(int x, int y,int z)
  28. {
  29.  
  30. if (x!=y)
  31. {
  32. if (ds[x].size()>=ds[y].size())
  33. swap(x,y);
  34.  
  35. for (int i=0;i<ds[x].size();i++)
  36. for (int j=0;j<g[ds[x][i]].size();j++)
  37. {
  38. int u=0;
  39. u=g[ds[x][i]][j];
  40. if (gr[u]==y && c[{ds[x][i],u}])
  41. {
  42. int o1=0;
  43. o1 =c[{ds[x][i],u}];
  44. for (int w=0;w<mp[o1].size();w++)
  45. pq[y].push(mp[o1][w]);
  46. }
  47.  
  48. }
  49. for (int i=0;i<ds[x].size();i++)
  50. {
  51. ds[y].push_back(ds[x][i]);
  52. st[y].insert(b[ds[x][i]]);
  53. gr[ds[x][i]]=y;
  54. }
  55.  
  56. st[x].clear();
  57. ds[x].clear();
  58.  
  59. while(!pq[x].empty())
  60. {
  61. int p=0;
  62. int p1=0;
  63. p=pq[x].top().first;
  64. p1=pq[x].top().second;
  65. pq[y].push({p,p1});
  66. pq[x].pop();
  67. }
  68.  
  69. while(!pq[y].empty() && abs(pq[y].top().first)<=st[y].size())
  70. {
  71. ans[pq[y].top().second]=z;
  72. pq[y].pop();
  73. }
  74. }
  75. }
  76.  
  77. int main()
  78. {
  79. scanf("%d%d%d",&n,&m,&q);
  80.  
  81. for (int i=1;i<=n;i++)
  82. scanf("%lld",&b[i]);
  83.  
  84. for (int i=1;i<=n;i++)
  85. {
  86. ds[i].push_back(i);
  87. st[i].insert(b[i]);
  88. gr[i]=i;
  89. }
  90. int p=0;
  91. for (int i=0;i<m;i++)
  92. {
  93. scanf("%d%d%d",&x,&y,&z);
  94. if (!ob[{x,y}])
  95. {
  96.  
  97. p++;
  98.  
  99. ob[{x,y}]=1;
  100. ob[{y,x}]=1;
  101. v[p-1]={z,{x,y}};
  102. g[x].push_back(y);
  103. g[y].push_back(x);
  104. }
  105. }
  106.  
  107.  
  108. sort(v,v+p);
  109.  
  110. for (int i=1;i<=q;i++)
  111. ans[i]=-1;
  112. int o=0;
  113. for (int i=1;i<=q;i++)
  114. {
  115. scanf("%d%d%lld",&x,&y,&z);
  116. if (x==y)
  117. {
  118. if (z<=1) {
  119. ans[i]=0;
  120. cnt[i]=1;
  121. }
  122. else
  123. pq[x].push({-z,i});
  124. } else
  125. {
  126. if (c[{x,y}]==0) {
  127. o++;
  128. c[{x,y}]=o;
  129. }
  130. mp[c[{x,y}]].push_back({-z,i});
  131. if (c[{y,x}]==0) {
  132. o++;
  133. c[{y,x}]=o;
  134. }
  135. mp[c[{y,x}]].push_back({-z,i});
  136. }
  137. }
  138.  
  139. for (int i=0;i<p;i++)
  140. spoj(gr[v[i].second.first],gr[v[i].second.second],v[i].first);
  141.  
  142. for (int i=1;i<=q;i++)
  143. printf("%lld\n",ans[i]);
  144.  
  145. return 0;
  146. }
  147.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:14:36: error: a space is required between consecutive right angle brackets (use '> >')
priority_queue <pair<long long ,int>> pq[maxi];
                                   ^~
                                   > >
prog.cpp:17:21: error: a space is required between consecutive right angle brackets (use '> >')
vector <pair<int,int>> mp[maxi];
                    ^~
                    > >
prog.cpp:21:30: error: a space is required between consecutive right angle brackets (use '> >')
pair<long long , pair<int,int>> v[maxi];
                             ^~
                             > >
prog.cpp:40:30: error: expected expression
           if (gr[u]==y && c[{ds[x][i],u}])
                             ^
prog.cpp:40:30: error: expected ']'
prog.cpp:40:29: note: to match this '['
           if (gr[u]==y && c[{ds[x][i],u}])
                            ^
prog.cpp:43:19: error: expected expression
            o1 =c[{ds[x][i],u}];
                  ^
prog.cpp:43:19: error: expected ']'
prog.cpp:43:18: note: to match this '['
            o1 =c[{ds[x][i],u}];
                 ^
prog.cpp:65:29: error: expected expression
                 pq[y].push({p,p1});
                            ^
prog.cpp:93:31: warning: format specifies type 'int *' but the argument has type 'long long *' [-Wformat]
         scanf("%d%d%d",&x,&y,&z);
                    ~~        ^~
                    %lld
prog.cpp:94:18: error: expected expression
         if (!ob[{x,y}])
                 ^
prog.cpp:94:18: error: expected ']'
prog.cpp:94:17: note: to match this '['
         if (!ob[{x,y}])
                ^
prog.cpp:99:16: error: expected expression
            ob[{x,y}]=1;
               ^
prog.cpp:99:16: error: expected ']'
prog.cpp:99:15: note: to match this '['
            ob[{x,y}]=1;
              ^
prog.cpp:100:16: error: expected expression
            ob[{y,x}]=1;
               ^
prog.cpp:100:16: error: expected ']'
prog.cpp:100:15: note: to match this '['
            ob[{y,x}]=1;
              ^
prog.cpp:101:17: error: expected expression
         v[p-1]={z,{x,y}};
                ^
prog.cpp:123:24: error: expected expression
            pq[x].push({-z,i});
                       ^
prog.cpp:126:15: error: expected expression
        if (c[{x,y}]==0)  {
              ^
prog.cpp:126:15: error: expected ']'
prog.cpp:126:14: note: to match this '['
        if (c[{x,y}]==0)  {
             ^
prog.cpp:128:11: error: expected expression
        c[{x,y}]=o;
          ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
stdout
Standard output is empty