Codeforces 576D Flights for Regular Customers

Source: Internet
Author: User
Tags bitset mul

Topic link Topic to the main effect

Given a forward graph, for the side I I have a limiting condition di d_i, which means that at the edge I I I must pass at least the other side of the Di d_i strip. At least a few sides are required to go from point 1 1 to n N. Solving

The more easily thought of violence is Fi,j f_{i, J} indicates that walking J-J Step can be exactly to I I point. Then Fi,j F_{i,j} can be transferred to Fk,j+1 F_{k, j+1}, K K is with I I have side e E and de≤j d_e \leq J.
This can only be done when di d_i is very small. So it doesn't seem to work.
Considering the previous idea of DNA sequence, the K-K-square of the adjacency matrix equals I I just walk K-K to J-J scheme number. Considering the constraints of the edges, if we have now passed the K-K step, then we can use only the edges of Di≤k d_i\le K. We can sort the edges in ascending order of Di d_i, add di d_i sequentially into the edge set, and segment the fast power transfer through the matrix. The arrival of the K-step between the maintenance point and the point goes. Note that we just need to know if we can get there and don't need to know the number of scenarios, then our matrix will always be 01 matrices. Using the naïve matrix multiplication in this problem will t drop, so with bitset acceleration. The accelerated matrix multiplication is as follows:

void Mul (bitset<n> *a, bitset<n> *b) {
    bitset<n> ret[n];
    Rep (i, 1, N) Rep (j, 1, N)
        if (A[i][j]) ret[i] |= b[j];
    Rep (i, 1, n) a[i] = Ret[i];
}

Bitset<n> A[n], b[n];
Mul (A, b);

The idea is that if

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.