# [connectivity of figure] 2018ecfinal A

Posted by Oubipaws on Sat, 09 Oct 2021 11:34:09 +0200

wxh solution
Station b
The blogger is too pigeon, so he plans to write an article on water
Meaning: given a bipartite graph G, there are n points on the left and right, and the edge weight range is [1,30]. definition G m G^m Gm is a bipartite graph, repeated m times, with m+1 layer points, and the connecting edge between layer i and layer i+1 is the same as G. about 1 ⩽ m ⩽ M 1\leqslant m \leqslant M 1 ⩽ m ⩽ M G m G^m Minimum spanning tree of Gm
n , m ⩽ 1 0 5 , ∣ E ∣ ⩽ 2 ∗ 1 0 5 n,m\leqslant 10^5,|E|\leqslant 2*10^5 n,m⩽105,∣E∣⩽2∗105
The blogger is too stupid to understand this question. After thinking about it, he adds a so-called rigorous statement that is useless
Solution: for 1 ⩽ w < 30 1\leqslant w <30 Each w of 1 ⩽ w < 30 is calculated ⩽ w \leqslant w ⩽ how many connecting blocks are formed on the edge of w
Suppose we handle it G m G^m Connection of Gm
Suppose we create a tree for each connection block in this connection case, and then specify FA for each point (the root of the connection block spanning tree does not need to specify fa)
Specifically, we'll do it for each point ( i , j ) (i,j) (i,j) establishment f a i , j fa_{i,j} fai,j, indicates what the father of the j-th point on the i-th layer is (also expressed as a binary, if there is no father, it is expressed as ( − 1 , − 1 ) (-1,-1) (−1,−1))
about f a i , j − > f i r s t ≠ − 1 fa_{i,j}->first\neq -1 fai,j − > first  = − 1, i + 1 ⩾ f a i , j − > f i r s t ⩾ i i+1\geqslant fa_{i,j}->first \geqslant i i+1⩾fai,j​−>first⩾i
Readers can stop and think about the spanning tree of this connection block
We from G m G^m Gm extended to G m + 1 G^{m+1} Gm+1
m+1 can be regarded as the union of the first m g and the last m G
But if you put G m G^m In Gm, the edges between the two layers are shifted to the right once to ensure connectivity. There are too many edges to deal with and there is no clue
So we propose an inductive hypothesis:
about 1 < i ⩽ m 1<i\leqslant m 1 < I ⩽ m, G i G_i Connectivity ratio of Gi G i − 1 G_{i-1} Gi − 1 +
definition G i G_i Gi​: 2 × n 2\times n two × n points, for f a i , j − > f i r s t ! = − 1 fa_{i,j}->first!=-1 fai,j − > first! = − 1, connection j − f a i , j − > s e c o n d + n j-fa_{i,j}->second+n j−fai,j​−>second+n
The so-called stronger connectivity is in G i − 1 G_{i-1} Connected in Gi − 1, in G i G_i Gi Li is also Unicom
So just put f a m , f a m + 1 fa_m,fa_{m+1} Edge irritability of fam, fam+1 + m + 1 , m + 2 m+1,m+2 M + 1 and M + 2 floors are enough
Sort it out, for 1 ⩽ i ⩽ m 1\leqslant i \leqslant m 1 ⩽ i ⩽ m we are all f a i fa_i Edge of fai +
m + 1 m+1 Layer m+1 is f a m , f a m + 1 fa_m,fa_{m+1} Connecting edge of fam, fam+1 +
m + 2 m+2 Layer m+2 is f a m + 1 fa_{m+1} Edge connection of fam+1 +
Therefore, it is necessary to maintain the edges of m+1 and m+2 layers f a m ′ , f a m + 1 ′ fa'_m,fa'_{m+1} fam ', fam+1', ensure that each connection block has exactly one spanning tree
As for how to get f a m ′ , f a m + 1 ′ fa'_m,fa'_{m+1} The edge of fam ', fam+1', the above solution, including the following code, are shown
Obviously, the above conclusion with stronger connectivity is still valid

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,M,m;
#define Maxn 100010
ll Ans[Maxn];
ll lastsum[Maxn];

struct Edge{int s,e;};
vector<Edge> edge[31];
vector<Edge> cur,nex;

int fa[Maxn<<1];
int find(int x){
if(fa[x]!=x)fa[x]=find(fa[x]);
return fa[x];
}

inline void solve(int x){
cur.clear();
ll res=0;
for(int i=1;i<=2*n;++i)fa[i]=i;
for(int i=0;i<edge[x].size();++i){
int fx=find(edge[x][i].s);
int fy=find(edge[x][i].e+n);
if(fx==fy)continue;
if(fx>n&&fy>n)cur.push_back((Edge){fx-n,fy-n});
if(fx>fy)swap(fx,fy);
fa[fx]=fy;
}
int siz1=0;
for(register int i=1;i<=n;++i)
if(find(i)==i)siz1++;
int siz2=0;
for(register int i=n+1;i<=2*n;++i)
if(find(i)==i)siz2++;
res+=siz1;
Ans[1]+=1ll*(2*n-siz1-siz2-lastsum[1])*x;
lastsum[1]=2*n-siz1-siz2;
for(register int i=2;i<=M;++i,cur=nex,nex.clear()){
for(int j=0;j<cur.size();++j){
int fx=find(cur[j].s);
int fy=find(cur[j].e);
if(fx==fy)continue;
if(fx>fy)swap(fx,fy);
fa[fx]=fy;
if(fx>n&&fy>n)nex.push_back((Edge){fx-n,fy-n}),siz2--;
else siz1--;
}
res+=siz1;
Ans[i]+=1ll*(1ll*n*(i+1)-res-siz2-lastsum[i])*x;
lastsum[i]=1ll*n*(i+1)-res-siz2;
}
}

inline void rd(int &x){
x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
}

int main(){
rd(n);rd(M);rd(m);
int s,e,t;
for(register int i=1;i<=m;++i){
rd(s);rd(e);rd(t);
for(register int j=t;j<=30;++j)edge[j].push_back((Edge){s,e});
}
for(register int i=1;i<=30;++i)solve(i);
for(register int i=1;i<=M;++i)printf("%lld\n",Ans[i]);
return 0;
}/*
4 4 8
3 4 12
1 1 20
1 3 22
4 2 12
4 4 2
2 2 2
1 2 2
1 4 2
*/


Topics: Algorithm Graph Theory