This question was done last night. I didn't come up with a good idea when I first started reading the question. Then I checked the question D. I found it was a suffix array, then I changed the template and handed it in ...... Unfortunately ...... WA, and then read the question again. The question is missing ...... Not only do I need to use a suffix array and a prefix array to find the public sub-fix, but also the smallest one. In addition, each string cannot be duplicated. Now I wonder if it will happen, then I saw the great C pass, and then I came back to check C. After reading it, I finally learned how to do it tomorrow.
C. Give a picture, and each point has the right to calculate the minimum cost and the number of solutions. The minimum cost is as follows: what can this post charge, I = j can be taken care of, or I can start from j to j, and then return to I from j. Note that the question is a single graph, So I starts from j to j, may not be able to return from j to I.
Train of Thought: according to the requirements of the question, the minimum cost is to find some points, and then the sum of the weights of these points is the smallest, in addition, all the points can be managed by themselves or by other points ). Why is the number of solutions required? Because if the values of the two points are the same and then connected to each other, there are two solutions! So here we can know what to do with strong connectivity!
The sum of the minimum values in each strong connection is the minimum cost. Then, the number of the minimum values in each strong connection is multiplied by the number of solutions !!! Because each node with the minimum tree value can establish a guard post, and then it is connected. Of course, it is just fine to create one. The number of solutions is just like this!
I knocked for an hour last night ...... An error occurred while trying to solve the scheme in strong connectivity. Only three columns were passed, and the change ended until the competition was over! Unfortunately! Just now, we can directly find the minimum cost and the number of solutions in do-while in Tarjan for strong connectivity. Yesterday we made a mistake in the main function, and I don't know why we can't do it, the practice is actually the same, alas ...... Write down last night
#include
#include
#include
#include #include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1.0)#define mem(a,b) memset(a,b,sizeof(a))#define sca(a) scanf("%d",&a)#define sc(a,b) scanf("%d%d",&a,&b)#define pri(a) printf("%d\n",a)#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define MM 400005#define MN 100005#define INF 1000000007#define eps 1e-7using namespace std;typedef long long ll;int n,m,cnt,tem,Count,DFN[MN],LOW[MN],vis[MN],suo[MN],q2[MN];vector
q[MN];int bb[MN];ll sum,tmp=1;void tarjan(int u){ int j,v; DFN[u]=LOW[u]=++cnt; vis[u]=1; q2[++tem]=u; for(j=0; j
bb[v]) x=1,y=bb[v]; else if(y==bb[v]) x++; } while(v!=u); sum+=y,tmp=tmp*x%INF; }}void solve(){ int v,i,j,kk=0; Count=cnt=tem=0; mem(DFN,0); for(i=1; i<=n; i++) if(!DFN[i]) tarjan(i); cout<
>n; int u,v; for(int i=1;i<=n;i++) sca(bb[i]); sca(m); for(int i=0;i