多校五 HDU

MZL‘s City

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0

Problem Description

MZL is an active girl who has her own country.

Her big country has N cities numbered from 1 to N.She has controled the country for so long and she only remebered that there was a big earthquake M years ago,which made all the roads between the cities destroyed and all the city became broken.She also remebered that exactly one of the following things happened every recent M years:

1.She rebuild some cities that are connected with X directly and indirectly.Notice that if a city was rebuilt that it will never be broken again.

2.There is a bidirectional road between city X and city Y built.

3.There is a earthquake happened and some roads were destroyed.

She forgot the exactly cities that were rebuilt,but she only knew that no more than K cities were rebuilt in one year.Now she only want to know the maximal  number of cities that could be rebuilt.At the same time she want you to tell her the smallest lexicographically plan under the best answer.Notice that 8 2 1 is smaller than 10 0 1.

Input

The first contains one integer T(T<=50),indicating the number of tests.

For each test,the first line contains three integers N,M,K(N<=200,M<=500,K<=200),indicating the number of MZL’s country ,the years happened a big earthquake and the limit of the rebuild.Next M lines,each line contains a operation,and the format is “1 x” , “2 x y”,or a operation of type 3.

If it’s type 3,first it is a interger p,indicating the number of the destoyed roads,next 2*p numbers,describing the p destoyed roads as (x,y).It’s guaranteed in any time there is no more than 1 road between every two cities and the road destoyed must exist in that time.

Output

The First line Ans is the maximal number of the city rebuilt,the second line is a array of length of tot describing the plan you give(tot is the number of the operation of type 1).

Sample Input

1
5 6 2
2 1 2
2 1 3
1 1
1 2
3 1 1 2
1 2

Sample Output

3
0 2 1

Hint

 No city was rebuilt in the third year,city 1 and city 3 were rebuilt in the fourth year,and city 2 was rebuilt in the sixth year.
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include<map>
#include<set>
#include<time.h>
#include<vector>
#include<queue>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define INF 0x3f3f3f3f
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
typedef pair<int , int> P;
#define max_n 200 + 10
#define max_m 500 + 10

struct Node1
{
    int time, x;
};

struct Node2
{
    int time, x, y;
};

struct Node3
{
    int time, p;
    vector<P> V;
};

Node1 s1[max_m];
Node2 s2[max_m];
Node3 s3[max_m];

int g[max_n][max_n];
int n, m, k;
int vis[max_n];
int mark[max_n];
int num[max_n];
int cnt1, cnt2, cnt3;
vector<int> ans;
int cnt;
int sum;

void dfs(int u)
{
    if(cnt == k)
        return ;
    //cout<<u<<" ";
    vis[u] = 1;
    if(mark[u])
    {
        num[u] = 0;
    }
    else
    {
        cnt++;
        num[u] = 1;
        mark[u] = 1;
    }
    for(int v = 1; v <= n; v++)
        if(!vis[v] && g[u][v])
    {
        dfs(v);
        num[u] += num[v];
    }
    return ;
}

void solve()
{
    for(int t = m; t > 0; t--)
    {
        if(cnt1 == 0)
            break ;
        if(s1[cnt1].time == t)
        {
            memset(vis, 0, sizeof vis);
            int x = s1[cnt1].x;
            cnt = 0;
            //cout<<"#";
            dfs(x);
            //cout<<endl;
            sum += cnt;
            ans.push_back(cnt);
            cnt1--;
        }
        else if(s2[cnt2].time == t)
        {
            int x = s2[cnt2].x, y = s2[cnt2].y;
            g[x][y] = g[y][x] = 0;
            cnt2--;
        }
        else
        {
            int x, y;
            for(int i = 0; i < s3[cnt3].p; i++)
            {
                x = s3[cnt3].V[i].first, y = s3[cnt3].V[i].second;
                g[x][y] = g[y][x] = 1;
            }
            cnt3--;
        }
    }
    printf("%d\n", sum);
    for(int i = ans.size() - 1; i >= 0; i--)
        i == 0 ? printf("%d\n", ans[i]) : printf("%d ", ans[i]);
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        sum = 0;
        ans.clear();
        memset(mark, 0, sizeof mark);
        cnt1 = cnt2 = cnt3 = 0;
        scanf("%d%d%d", &n, &m, &k);
        int op, u, v;
        for(int i = 1; i <= m; i++)
        {
            scanf("%d%d", &op, &u);
            if(op == 1)
            {
                s1[++cnt1] = Node1{i, u};
            }
            else if(op == 2)
            {
                scanf("%d", &v);
                s2[++cnt2] = Node2{i, u, v};
                g[u][v] = g[v][u] = 1;
            }
            else
            {
                s3[++cnt3].p = u;
                s3[cnt3].time = i;
                int x, y;
                s3[cnt3].V.clear();
                for(int j = 0; j < u; j++)
                {
                    scanf("%d%d", &x, &y);
                    s3[cnt3].V.push_back({x, y});
                    g[x][y] = g[y][x] = 0;
                }
            }
        }
        solve();
    }
    return 0;
}

/*

100

5 7 5
2 1 2
2 2 3
2 3 4
2 4 5
1 2
3 1 2 3
1 3

5 7 5
2 1 2
2 2 3
2 3 4
2 4 5
1 2
3 1 2 3
1 2

4 7 3
2 1 2
2 2 3
2 3 4
2 4 1
1 4
3 1 1 2
1 1

5 7 3
2 1 2
2 2 3
2 3 5
2 3 4
1 1
3 1 2 3
1 2

*/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-13 05:46:22

多校五 HDU的相关文章

多校训练hdu --Nice boat(线段树,都是泪)

Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 47 Accepted Submission(s): 10 Problem Description There is an old country and the king fell in love with a devil. The devil always ask

判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

1 // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence 2 // 题意:三种操作,1增加值,2开根,3求和 3 // 思路:这题与HDU 4027 和HDU 5634 差不多 4 // 注意开根号的话,遇到极差等于1的,开根号以后有可能还是差1.如 5 // 2 3 2 3... 6 // 8 9 8 9... 7 // 2 3 2 3... 8 // 8 9 8 9... 9 // 剩下就是遇到区间相等的话,就直接开根号不往下传 10 11 12

多校 #5 hdu 5784 How Many Triangles

http://acm.hdu.edu.cn/showproblem.php?pid=5784 给定平面上互不相同的n个点,求所有锐角三角形的个数.3<=n<=2000 锐角三角形因为要三个角都是锐角,所以限制条件多.即使枚举一个点,另外两条边用极角排序,也只能维护一个锐角,剩下的两个角难于统计. 但是,如果换一种思路,统计所有直角.钝角以及三点共线的个数 ,问题就简单多了.因为因为只有一个直角或钝角或平角,只需依次对每个点,统计以它为哪一个特殊角的直角.钝角.平角三角形有多少即可. 具体做法是

南校五天集训游记

住四人间,我爽了 宿舍开灯有莫名的延迟??? 上床的梯子横杆很细,巨痛!!!\(SP\) \(\nearrow\) \(FA\) \(\searrow\) 大家在宿舍里不断发~财~(\(fafafa\)) 饭菜很便宜,早饭六元,午饭晚饭八元(因为我们被归为了国庆留校生) 山大附中和石门也来听,还有润德的一个小伙子,总共\(28\)人 被初中学长爆踩 \(Day3\)热身赛因\(Win10\)更新卡我半小时??? \(ysq\):留了长发(因为以前\(zzj\)不让留???),还有终极蛇皮笑声,\

17多校6 HDU - 6102

题意:给一个排列p,m次查询l,r,\(\sum_{i=l}^r\sum_{j=i+1}^r\sum_{k=j+1}^r[gcd(p_i,p_j)==p_k]p_k\) 题解:离线,枚举右端点,对于每个数在i位置的数\(p_i\),考虑前面所有是\(p_i\)的倍数的位置,假设是\(t_1,t_2,...,t_x\)从后往前枚举,那么对于\(t_j\)来说,所有在\(t_j\)到\(i\)之间的位置,假设有k个位置和\(t_j\)gcd为\(a_i\),那么对于右端点在i,左端点在\(t_j\)

2018 多校3 hdu 6319 6322 6324 6330

6319 a题 才看完单调队列(待补 6322 d题 一个数论题,找规律就出来了 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 int main() 8 { 9 long long n,k; 10 cin>>n; 11 while(n--){ 12 cin>>k; 13 if(k==1) cout<<

迎新(一)

我只能说,我已经到学校了,用一句话带过我的假期,因为确实过的简简单单. 那么,就正式过渡为辅导员助理,新的身份适应的还是比较顺利的,毕竟假期里也水了很长时间的群.今天上午我们五个助导在辅导员的带领下领取了卫生工具,并检查了校内五号楼的一些宿舍,仅仅是要求我们检查而已,并不是说已经分给了我们数统.其实校五的环境还是很好的,地方宽敞,有阳台,推开房门便有一阵凉风袭来,并且也是有独卫的,想来比我的校二住的舒服,但我已经习惯住在这里,各种条件也适应的不错,便懒得动弹,赖在这里四年即可. 检查宿舍的时候还

2014多校联合五(HDU 4911 HDU 4915 HDU 4920)

HDU 4911 Inversion 题意:n个数字  通过k次相邻交换  使得逆序对数最少 思路:如果序列为 XXXABYYY  假设A和B位置互换  易知X和AB.Y和AB的逆序对数不变  换句话说一次交换最多使逆序对减少1  那么只需要求原逆序对数和k进行比较即可 代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 100100 type

2014多校第五场1010 || HDU 4920 Matrix multiplication(矩阵乘法优化)

题目链接 题意 : 给你两个n*n的矩阵,然后两个相乘得出结果是多少. 思路 :一开始因为知道会超时所以没敢用最普通的方法做,所以一直在想要怎么处理,没想到鹏哥告诉我们后台数据是随机跑的,所以极端数据是不可能会有的,而我们一开始一直在想极端数据能接受的方法......后来看了鹏哥的做法,就是把是0的地方都跳过就可以了,用矩阵保存前一个非0数的位置是多少.二师兄给我看了一个代码,人家根本没用别的优化,直接将最里层k的循环提到了最外层,然后就AC了,对此我表示无语. 1 #include <cstd