A. Arrow a Row
【题意】
给出一个长为 n n n 的字符串 S S S 只由 > 和 - 构成,∑ n ≤ 5 e 5 \sum n \le 5e5 ∑ n ≤ 5 e 5 。一次染色选择一段长大于等于 5 5 5 的区间,染色为 >->>> 的形式,即最左侧一个和最右侧三个染色为 > 其余染色为 -。构造不多于 n n n 次的构造方案。
【题解】
显然 S S S 最左侧和最右侧三个必须是 >,然后不妨把 > 和 - 分段,然后如果最右侧的段左边没有 - 即 S S S 中没有 - 也不行。判断之后我们可以一直选最右侧三个,然后左边的箭头从左往右一个一个构造。但最后一段里的 > 不能当作左边界构造。我们找到倒数第二段最后一个 > 再把最后一段里其他 > 构造出来。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 #include <bits/stdc++.h> using namespace std;int T,n,cnt;string s; signed main () { cin>>T; while (T--){ cin>>s; n=s.length (); if (s[0 ]=='-' || s[n-1 ]=='-' ){ cout<<"No\n" ; continue ; } int tmp=n-1 ; while (s[tmp]=='>' && tmp>=0 ) --tmp; if (tmp<0 ){ cout<<"No\n" ; continue ; } ++tmp; if (n-tmp<3 ){ cout<<"No\n" ; continue ; } cout<<"Yes " ; cnt=0 ; int last=-1 ; for (int i=0 ;i<tmp;i++){ if (s[i]=='>' ){ ++cnt; last=i; } } for (int i=n-2 ;i-2 >=tmp;i--){ ++cnt; } cout<<cnt<<'\n' ; last=-1 ; for (int i=0 ;i<tmp;i++){ if (s[i]=='>' ){ last=i; cout<<i+1 <<' ' <<n-1 -i+1 <<'\n' ; } } for (int i=n-2 ;i-2 > = tmp;i--){ cout<<last+1 <<' ' <<i - last + 1 < < '\n' ; } } return 0 ; }
B. Athlete Welcome Ceremony
【题意】
给一个长为 n ≤ 300 n \le 300 n ≤ 3 0 0 的字符串仅含 a,b,c,?,Q ≤ 1 0 5 Q \le 10^5 Q ≤ 1 0 5 次询问,每次给出 0 ≤ a , b , c ≤ 300 0\le a,b,c \le 300 0 ≤ a , b , c ≤ 3 0 0 表示可用的 a,b,c 数量。求把 ? 填完且没有相邻相同字母的方案数。对 1 0 9 + 7 10^9 + 7 1 0 9 + 7 取模。
【题解】
直接设 f i , j , k , 0 / 1 / 2 f_{i,j,k,0/1/2} f i , j , k , 0 / 1 / 2 表示前 i i i 个位置,填了 j j j 个 a a a ,k k k 个 b b b ,且结尾是 a / b / c a/b/c a / b / c 的方案数。那么转移时看第 i i i 的位置填哪一个或者不填转移即可。
统计答案时即求 ∑ i ∑ j f n , i , j , 0 / 1 / 2 \sum_{i}\sum_{j} f_{n,i,j,0/1/2} ∑ i ∑ j f n , i , j , 0 / 1 / 2 ,我们直接枚举 i i i ,然后对于 j j j 就是区间和直接前缀和即可。
复杂度 O ( n 3 + n Q ) O(n^3 + nQ) O ( n 3 + n Q ) 。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 #include <bits/stdc++.h> #define int long long using namespace std;#define in read() inline int read () { int p=0 ,f=1 ; char c=getchar (); while (!isdigit (c)){if (c=='-' ) f=-1 ;c=getchar ();} while (isdigit (c)){p=p*10 +c-48 , c=getchar ();} return p*f; } const int N=305 ,P=1e9 +7 ;int n,Q;string s; int f[2 ][N][N][3 ],cnt[N],sum[N][N],p;signed main () { n=in,Q=in; cin>>s; for (int i=1 ;i<=n;i++){ cnt[i]=cnt[i-1 ]; if (s[i-1 ]=='?' ) cnt[i]++; } p=0 ; if (s[0 ]=='?' ) f[p][1 ][0 ][0 ]=1 ,f[p][0 ][1 ][1 ]=1 ,f[p][0 ][0 ][2 ]=1 ; else f[p][0 ][0 ][s[0 ]-'a' ]=1 ; for (int i=2 ;i<=n;i++){ p^=1 ; memset (f[p],0 ,sizeof (f[p])); if (s[i-1 ]=='?' ){ for (int j=0 ;j<=cnt[i];j++) for (int k=0 ;j+k<=cnt[i];k++){ if (j>0 ) f[p][j][k][0 ] = (f[p^1 ][j-1 ][k][1 ] + f[p^1 ][j-1 ][k][2 ])%P; if (k>0 ) f[p][j][k][1 ] = (f[p^1 ][j][k-1 ][0 ] + f[p^1 ][j][k-1 ][2 ])%P; if (cnt[i]-j-k>0 ) f[p][j][k][2 ] = (f[p^1 ][j][k][0 ] + f[p^1 ][j][k][1 ])%P; } }else { for (int j=0 ;j<=cnt[i];j++) for (int k=0 ;j+k<=cnt[i];k++) f[p][j][k][s[i-1 ]-'a' ] = (f[p^1 ][j][k][0 ] + f[p^1 ][j][k][1 ] + f[p^1 ][j][k][2 ] - f[p^1 ][j][k][s[i-1 ]-'a' ])%P; } } for (int i=0 ;i<=300 ;i++){ sum[i][0 ]=(f[p][i][0 ][0 ]+f[p][i][0 ][1 ]+f[p][i][0 ][2 ])%P; for (int j=1 ;j<=300 ;j++) sum[i][j]=(sum[i][j-1 ]+f[p][i][j][0 ]+f[p][i][j][1 ]+f[p][i][j][2 ])%P; } for (int T=1 ;T<=Q;T++){ int a=in,b=in,c=in,res=0 ; for (int i=0 ;i<=a&&i<=cnt[n];i++){ int st=cnt[n]-i-c,ed=b; if (st>ed||st > 300 )continue ; st=max (0ll ,st); ed=min (300ll ,ed); if (st==0 ) res+=sum[i][ed]; else res+=sum[i][ed]-sum[i][st-1 ]; } cout<<(res%P+P)%P< < '\n' ; } return 0 ; }
E. Disrupting Communications
【题意】
给出一棵 n n n 个节点的树,q q q 个询问,每次询问给出两个点 u , v u,v u , v 。
要求选择一个子联通块,删去之后可以把 u , v u,v u , v 两点分割。特殊的,删除 u , v u,v u , v 中任何一个或者都删了也算分割。
对每次询问求出选择的方案数。对 998244353 998244353 9 9 8 2 4 4 3 5 3 取模。
n , q ≤ 1 0 5 , ∑ n , q ≤ 3 × 1 0 5 n,q\le 10^5,\sum n,q \le 3\times 10^5 n , q ≤ 1 0 5 , ∑ n , q ≤ 3 × 1 0 5
【解法】
考虑进行dp预处理,f i f_i f i 表示以 i 为联通块中深度最浅的那个点的联通块的方案数,g i g_i g i 表示包含 i 节点的联通块个数。
f x = ∏ y ∈ s o n [ x ] ( f y + 1 ) f_x = \prod_{y\in son[x]}(f_y + 1) f x = ∏ y ∈ s o n [ x ] ( f y + 1 )
g y = ( g x f y + 1 + 1 ) f y g_y = (\frac{g_x}{f_y+1} + 1)f_y g y = ( f y + 1 g x + 1 ) f y
可以通过两次dfs求出来。所以最后的答案就是 u 和 v 到 lca 的链上的 f 之和,加上 lca 的 g 就可以。可以求出lca后直接树上差分就行。
然后就会开心的发现WA掉了。
什么神人卡逆元
因为发现求 g g g 的时候用到了除法,在同余意义下处理方式一般都是求逆元,但是是可以被卡掉的。构造一组数据做到某个位置的 f x + 1 f_x + 1 f x + 1 是模数的倍数,就会变成除以 0。就算求了逆元也是乘一个 0。
处理方法是先改一下 g x g_x g x 的定义,改为最多选 x x x 的父亲的部分,的方案数。
g y = g x × f p r e y × f s u f y g_y = g_x\times fpre_y\times fsuf_y g y = g x × f p r e y × f s u f y ,这里的pre和suf是对 x 的子树进行的pre和suf计算。这样就可以避免掉逆元。
然后一定要注意,在求 g x g_x g x 的时候,一定要把 x 的所有儿子的 g 值求出来之后,再进行递归求子孙的 g 值,否则在递归过程中 fpre 和 fsuf 会发生改变。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 const int N = 100005 , M = 998244353 ;int n , q ;int f[N] , g[N] , s[N];int siz[N] , dep[N] , fa[N] , son[N] , top[N];vector < int > vc[N] ; void dfs (int x) { f[ x ] = 1 ; siz[ x ] = 1 ; son[ x ] = 0 ; for (int y:vc [ x ]) { dep[ y ] = dep[ x ] + 1 ; fa[ y ] = x; dfs (y) ; f[ x ] = f[ x ] * (f[ y ] + 1 ) % M; if ( siz [ y ] > siz [ son [ x ] ] ) son [ x ] = y ; siz [ x ] += siz [ y ] ; } } int fpre[N],fsuf[N];void dfs0 (int x) { int sz = vc [ x ] .size (); fpre [ 0 ] = 1 ; fsuf [ sz + 1 ] = 1 ; for ( int i = 1 ; i <= sz ; ++ i ) fpre [ i ] = fpre [ i - 1 ] * ( f [ vc[x][i-1 ] ] + 1 )%M; for ( int i = sz ; i > = 1 ; -- i ) fsuf [ i ] = fsuf [ i + 1 ] * ( f [ vc[x][i-1 ] ] + 1 )%M; for ( int i = 1 ; i <= sz ; ++ i ) { int y=vc[x][i-1 ]; g[y]=(g[x]*fpre[i-1 ]%M*fsuf[i+1 ]+1 )%M; } for ( int i = 1 ; i <= sz ; ++ i ) { int y=vc[x][i-1 ]; s [ y ] = ( s [ x ] + f [ y ] ) % M ; dfs0 (y) ; } } void dfs1 ( int x , int topf ) { top [ x ] = topf ; if ( son [ x ] ) dfs1 ( son [ x ] , topf ) ; for ( int y : vc [ x ] ) { if ( y == son [ x ] ) continue ; dfs1 ( y , y ) ; } } int lca ( int x , int y ) { while ( top [ x ] != top [ y ] ) { if ( dep [ top [ x ] ] < dep [ top [ y ] ] ) swap ( x , y ) ; x = fa [ top [ x ] ] ; } if ( dep [ x ] < dep [ y ] ) return x; return y; } int query ( int x , int y ) { int xy = lca ( x , y ) ; int res = s [ x ] + s [ y ] +(M-s [ xy ] ) * 2 + g [ xy ] ; res %= M ; return res ; } void solve () { n = read () , q = read () ; for ( int i = 1 ;i <= n ; ++ i ) vc [ i ] .clear ( ) ; for ( int i = 2 ;i <= n; ++ i) { int x = read (); vc[x] .push_back (i) ; } dfs (1 ); g [ 1 ] = 1 ; s [ 1 ] = f [ 1 ] ; dfs0 (1 ); dfs1 (1 ,1 ); for (int i=1 ;i<=n;+ + i)g[i]=g[i]*f[i]%M; while ( q -- ) { int x = read () , y = read (); cout << query ( x , y ) < < "\n" ; } } signed main () { int T = read (); while ( T - - ) { solve () ; } return 0 ; }
G. Expanding Array
【题意】
给出一个序列 a 1 , a 2 , ⋯ , a n a_1,a_2,\cdots,a_n a 1 , a 2 , ⋯ , a n ,每次可以选择相邻两个整数,在中间加入 a ⊕ b a\oplus b a ⊕ b ,其中 ⊕ \oplus ⊕ 指按位与,按位或,按位异或。
求最后序列中本质不同的数最多有多少个。
n ≤ 1 0 5 , a i ≤ 1 0 9 n\le 10^5,a_i \le 10^9 n ≤ 1 0 5 , a i ≤ 1 0 9
【解法】
发现进行二进制运算时,每一位的情况只有四种,( 0 , 0 ) , ( 0 , 1 ) , ( 1 , 0 ) , ( 1 , 1 ) (0,0),(0,1),(1,0),(1,1) ( 0 , 0 ) , ( 0 , 1 ) , ( 1 , 0 ) , ( 1 , 1 ) ,所以可以直接考虑 0011 0011 0 0 1 1 和 0101 0101 0 1 0 1 ,这两个数用什么方法可以拼出所有能凑出来的数,发现最多拼出 8 个数。
所以直接每次拎出两个数进行计算,把所有可能的数都加到map里,最后统计个数就行了。
进行异或运算的时候 z = x ⊕ y z = x \oplus y z = x ⊕ y ,同样有 y = x ⊕ z y = x\oplus z y = x ⊕ z ,所以可以先把相邻两个数 x , y x,y x , y 变成 x , y , x ⊕ y , x , y , x ⊕ y , x , y , ⋯ x,y,x\oplus y,x,y,x\oplus y,x,y,\cdots x , y , x ⊕ y , x , y , x ⊕ y , x , y , ⋯
之后进行按位与和按位或运算即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 void calc (int x , int y) { int z = x ^ y , u ; if ( ! mp [ x ] ) add ( x ); if ( ! mp [ y ] ) add ( y ); if ( ! mp [ z ] ) add ( z ); u = x & y ; if ( ! mp [ u ] ) add ( u ) ; u = x | y ; if ( ! mp [ u ] ) add ( u ) ; u = x & z ; if ( ! mp [ u ] ) add ( u ) ; u = x | z ; if ( ! mp [ u ] ) add ( u ) ; u = y & z ; if ( ! mp [ u ] ) add ( u ) ; u = y | z ; if ( ! mp [ u ] ) add ( u ) ; u = x | y | z ; if ( ! mp [ u ] ) add ( u ) ; u = x & y & z ; if ( ! mp [ u ] ) add ( u ) ; }
I. Good Partitions
【题意】
给出长为 n ≤ 2 × 1 0 5 n \le 2\times10^5 n ≤ 2 × 1 0 5 的数组 a , a i ≤ 2 × 1 0 9 a,a_i \le 2\times10^9 a , a i ≤ 2 × 1 0 9 。若将 a a a 每 k k k 个分为一段,最后一段允许不满 k k k 个后,每一段内部都不减,则 k k k 是合法的。求 1 ≤ k ≤ n 1\le k \le n 1 ≤ k ≤ n 中有多少个合法的 k k k 。q ≤ 2 × 1 0 5 q \le 2\times 10^5 q ≤ 2 × 1 0 5 次单点修改并求新的答案。
【题解】
我们可以把 n n n 个位置视为 n − 1 n - 1 n − 1 个限制,即 a i ≤ a i + 1 a_i \le a_{i + 1} a i ≤ a i + 1 或 (a_i > a_{i + 1})\and(k|i) 。即要么不减要么断开。换言之我们把所有大于的下标求最大公约数,再求这个数的因数个数即可。
对于求最大公约数的部分,单点修改线段树即可。对于求因数个数的部分,积性函数线性筛即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 const int N=200005 ;int pr[N],cnt,cntd[N],ok[N],re[N];inline int prepare () { ok[1 ]=1 ; cntd[1 ]=1 ; for (int i=2 ;i<N;++i) { if (!ok[i]) { cntd[i]=2 ; re[i]=1 ; pr[++cnt]=i; } for (int j=1 ;j<=cnt&&pr[j]*i<N;++j) { ok[pr[j]*i]=1 ; if (i%pr[j]==0 ) { re[i*pr[j]]=re[i]; if (re[i]==1 )cntd[i*pr[j]]=cntd[i]+1 ; else cntd[i*pr[j]]=cntd[re[i]]*cntd[i*pr[j]/re[i]]; break ; } re[i*pr[j]]=i; cntd[i*pr[j]]=cntd[i]*2 ; } } } inline int gcd (int a,int b) {return b?gcd (b,a%b):a;}int T,n,q,a[N],sum[N<<2 ];inline void built (int p,int l,int r) { if (l==r){ if (l<n&&a[l]>a[l+1 ]) sum[p]=l; else sum[p]=0 ; return ; } int mid=(l+r)>>1 ; built (p<<1 ,l,mid); built (p<<1 |1 ,mid+1 ,r); sum[p]=gcd (sum[p<<1 ],sum[p<<1 |1 ]); } inline void change (int p,int l,int r,int x,int d) { if (l==r){ a[l]=d; if (l<n&&a[l]>a[l+1 ]) sum[p]=l; else sum[p]=0 ; return ; } int mid=(l+r)>>1 ; if (x<=mid) change (p<<1 ,l,mid,x,d); else change (p<<1 |1 ,mid+1 ,r,x,d); sum[p]=gcd (sum[p<<1 ],sum[p<<1 |1 ]); } signed main () { prepare (); T=in; while (T--){ n=in,q=in; for (int i=1 ;i<=n;i++) a[i]=in; built (1 ,1 ,n); if (sum[1 ]==0 ) cout<<n<<'\n' ; else cout<<cntd[sum[1 ]]<<'\n' ; for (int i=1 ;i<=q;i++){ int p=in,v=in; change (1 ,1 ,n,p,v); if (p>1 ) change (1 ,1 ,n,p-1 ,a[p - 1 ]); if (sum[1 ]= = 0 ) cout<<n<<'\n' ; else cout<<cntd[sum[1 ]]< < '\n' ; } } return 0 ; }
K. Magical Set
【题意】
起初,有 n n n 个不同的数。n ≤ 300 , a i ≤ 1 0 9 n\le 300,a_i \le 10^9 n ≤ 3 0 0 , a i ≤ 1 0 9
每次操作,选择一个数,将其变成它的一个真因数,并获得 1 1 1 分。需要保证在每次操作完成之后,任意两个数不相同。
求最大得分。
【思路】
若 x = ∏ p i c i x = \prod p_i^{c_i} x = ∏ p i c i ,设 s u m x = ∑ c i sum_x = \sum c_i s u m x = ∑ c i 。
对于每个数 a i a_i a i ,确定它最后会变成的数 b i b_i b i 。操作的过程一定是每次除以一个质因数,这样能最大化的分;也可以猜测,合理调整操作顺序,一定可以保证任意时刻没有相等的两个数。
【题解】
问题转化为:为每一个初始的 a i a_i a i 选择匹配一个 b i b_i b i 获得 s u m a i b i sum_{\frac{a_i}{b_i}} s u m b i a i 的得分,就是一个最大权值完美匹配问题。
一个小优化就是,虽然 a i a_i a i 的因数最多能有 1000 1000 1 0 0 0 个,但是我们只需要取其中权值最大的 300 300 3 0 0 个来建图就行啦。
考场上用的 D i n i c Dinic D i n i c 费用流实现的最大权值完美匹配。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 const int N=1e5 +5 ,INF=1e9 +2 ;int ok[N],pr[N],cnt,sum[N];int prepare () { sum[1 ]=0 ; ok[1 ]=1 ; for (int i=2 ;i<N;++i) { if (!ok[i]) { pr[++cnt]=i; sum[i]=1 ; } for (int j=1 ;j<=cnt&&pr[j]*i<N;++j) { ok[pr[j]*i]=1 ; sum[pr[j]*i]=sum[i]+1 ; if (i%pr[j]==0 )break ; } } } const int M=303 *303 +303 ;struct Edge { int v,cost,nxt,flow; }e[M*4 ]; int head[M],cur[M],dis[M],sze=1 ,vis[M];void link (int u,int v,int flow,int cost) { ++sze; e[sze]={v,cost,head[u],flow}; head[u]=sze; } void Elink (int u,int v,int flow,int cost) { link (u,v,flow,cost); link (v,u,0 ,-cost); } int n;vector<pair<int ,int >>SS[303 ]; int b[303 *303 ],len,S,T;unordered_map<int ,int >F; bool spfa () { for (int i=1 ;i<=T;++i)dis[i]=-INF,vis[i]=0 ; dis[S]=0 ; queue<int >q; q.push (S);vis[S]=1 ; while (!q.empty ()) { int u=q.front ();q.pop (); vis[u]=0 ; for (int i=head[u];i;i=e[i].nxt) { int v=e[i].v; if (e[i].flow>0 &&dis[v]<dis[u]+e[i].cost) { dis[v]=dis[u]+e[i].cost; if (!vis[v])q.push (v),vis[v]=1 ; } } } return dis[T]>-INF; } int dfs (int u,int flow) { if (u==T||flow==0 )return flow; int nwflow=0 ; vis[u]=1 ; for (int &i=cur[u];i;i=e[i].nxt) { int v=e[i].v,d; if (!vis[v]&&dis[v]==dis[u]+e[i].cost&&e[i].flow>0 &&(d=dfs (v,min (flow,e[i].flow)))>0 ) { nwflow+=d; e[i].flow-=d; e[i^1 ].flow+=d; flow-=d; if (flow==0 )break ; } } return nwflow; } int MaxCost () { int flow=0 ,cost=0 ; while (spfa ()) { for (int i=1 ;i<=T;++i)cur[i]=head[i]; int nwflow=dfs (S,INF); cost+=nwflow*dis[T]; flow+=nwflow; } assert (flow==n); return cost; } vector<pair<int ,int >>TT; int nwsum;void dfs (int u,int nw,int nwcnt,int nwid) { if (u==TT.size ()) { SS[nwid].push_back ({-(nwsum-nwcnt),nw}); return ; } int prod=1 ,ber=TT[u].first; for (int i=0 ;i<=TT[u].second;++i) { dfs (u+1 ,nw*prod,nwcnt+i,nwid); prod*=ber; } } int main () { prepare (); n=read (); for (int i=1 ;i<=n;++i) { int x=read (); TT.clear (); nwsum=0 ; for (int j=1 ;pr[j]*pr[j]<=x;++j) if (x%pr[j]==0 ) { int cnt=0 ; while (x%pr[j]==0 )x/=pr[j],++cnt; TT.push_back ({pr[j],cnt}); nwsum+=cnt; } if (x>1 )TT.push_back ({x,1 }),++nwsum; dfs (0 ,1 ,0 ,i); sort (SS[i].begin (),SS[i].end ()); while (SS[i].size ()>n)SS[i].pop_back (); for (auto y:SS[i]) b[++len]=y.second; } sort (b+1 ,b+len+1 ); len=unique (b+1 ,b+len+1 )-b-1 ; S=n+len+1 ;T=n+len+2 ; for (int i=1 ;i<=len;++i) F[b[i]]=i,Elink (i+n,T,1 ,0 ); for (int i=1 ;i<=n;++i) { Elink (S,i,1 ,0 ); for (auto y:SS[i]) Elink (i,F[y.second]+n,1 ,-y.first); } printf ("%d" ,MaxCost ()); return 0 ; }