HDU 3047 Zjnu Stadium (with permission and query set)

Source: Internet
Author: User

HDU 3047 Zjnu Stadium (with permission and query set)

Train of Thought: note that the number of rows is infinite. Therefore, two people can be separated by another person x far (separated by x columns, not the same row) at the same time. That is to say, the only difference between the two is that, the distance between the two people is in conflict with that mentioned earlier. So how can we determine the contradiction? Because there is an indirect correlation between each person, we need to deal with the distance of a set, so we can use the permission and query set to deal with it well.

For details, see the code:

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           
             # Include
            
              # Include
             # Include
              
                # Define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) using namespace std; typedef long ll; typedef long double ld; const ld eps = 1e-9, PI = 3.1415926535897932384626433832795; const int mod = 1000000000 + 7; const int INF = 0x3f3f3f; // & 0x7FFFFFFFconst int seed = 131; const ll INF64 = ll (1e18); const int maxn = 50000 + 10; int T, n, m, p [maxn], dist [maxn]; void init (int n) {for (int I = 1; I <= n; I ++) {p [I] = I; dist [I] = 0 ;}} int _ find (int x ){ If (p [x] = x) return p [x]; int fa = p [x]; p [x] = _ find (p [x]); dist [x] + = dist [fa]; // maintain the return p [x];} inline bool BIN (int, int B, int c) {int x = _ find (a); int y = _ find (B); if (x = y) {if (dist [a] + c! = Dist [B]) return false; // determines whether a conflict exists. return true;} p [y] = x; dist [y] = dist [a]-dist [B] + c; // calculate the relative distance. If a and B are separated from c, add or subtract the value based on the vector, you can find the dist [y]. For more information, see return true;} int a, B, c; int main () {while (~ Scanf ("% d", & n, & m) {init (n); int ans = 0; while (m --) {scanf ("% d", & a, & B, & c); if (! BIN (a, B, c) ++ ans;} printf ("% d \ n", ans);} return 0 ;}
              
            
           
          
         
        
       
      
     
    
   
  
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.