A. Case of Matryoshkas
As long as the statistics and 1 connected to the number of good (1,2,3..K), not connected to disconnect, the rest of the chain, each chain to be broken, the price is the length of the chain I-1, and finally together, the cost is the number of all nodes-1
The array is 10000 FST.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <iostream>5 using namespacestd;6 7typedefLong Longll;8 9 inta[100000+5];Ten One intMain () { A intN, K, TP, M; - intAns =0, cnt =0; -scanf"%d%d", &n, &k); the for(inti =1; I <= K; i++) { -scanf"%d", &m); - BOOLFlag =0; - for(intj =0; J < M; J + +) { +scanf"%d", &tp); - if(TP = =1) { +Flag =1; Aa[1] =1; at for(intK =2; K <= m; k++) { -scanf"%d", &a[k]); - } - for(intK =1; K <= m; k++) { - if(A[k] = =k) { -cnt++; in}Else { - Break; to } + } -Ans + = mCNT; the Break; * } $ }Panax Notoginseng if(!flag) ans + = m1; - } theAns + = nCNT; +printf"%d\n", ans); A return 0; the}
View Code
Codeforces Round #310 (Div. 1)