BAPC 2019 E.Exits in Excess(思维)

You own a disco called the Boogie Always Persists Club.The club is famous for its multiple interconnected rooms to twist and shout in. The rooms and the corridors between them form a maze-like structure and for added bonus you have made all the corridors one-way. However, it turns out not everyone is as happy with your club as you are. Recently the fire safety inspectors came by and they were not amused by what they saw: if a fire were to break out in one of the rooms, people would have great difficulty finding the fire exits and might even start running around in circles! They find this completely unacceptable and order you to improve things as quickly as possible. They insist that you have to make sure that no one can run around in circles in the club by removing some of the corridors between the rooms.

You, on the other hand, want to retain the attractiveness of the rooms. You do not want to remove too many corridors, because then people will no longer visit your club. You decide that at most half of the corridors may be removed.

Given the layout of the club, remove at most half of the corridors so that no cycles remain.

INPUT:

• One line containing the number of rooms 1 ≤ n ≤ 10^5 and the number of corridors 0 ≤ m ≤ 2 · 10^5.

 • Then follow m lines, each containing two different 1-based integers u and v indicating a corridor from room u to room v. There will be no corridor from a room to itself, nor will there be more than one corridor from one room to any other single room.

OUTPUT:

• On the first line, print a single integer 0 ≤ r ≤ m/2, the number of corridors to be removed. 

• Then print r lines containing the 1-based indices of the corridors that need to be removed to ensure that dancers cannot go around in circles in the disco anymore.

 If there are multiple valid solutions, you may output any one of them.

Sample Input 4-5 Sample Output 4-5
4 5
1 2
2 3
2 4
3 1
4 1
2
4
5
4 3
1 2
2 3
3 4
1
2

本题答案不唯一,符合要求的答案均正确

样例输入1复制

2 2
1 2
2 1

样例输出1复制

1
2

样例输入2复制

3 3
1 2
2 3
3 1

样例输出2复制

1
1

样例输入3复制

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

样例输出3复制

0

这场打的好惨啊qwq...当时没有仔细想这个题......

计蒜客现在才有了题库链接,今天来补题惹...

 

题意:

n个点,m条有向边,删除最多一半的边使得图中没有自环

思路:

比较 u < v 的边数和 u > v 的边数,把边数少的一部分都删掉

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 +7;
const int N = 2e5 + 10;

struct node
{
    int u, v;
}s[N];

int main()
{
    int n, m;
    while(~scanf("%d%d", &n, &m))
    {
        int a = 0, b = 0;
        for(int i = 1; i <= m; ++i)
        {
            scanf("%d%d", &s[i].u, &s[i].v);
            if(s[i].u < s[i].v)
                a++;
            else
                b++;
        }
        bool flag = 0;
        if(a > b)
            flag = 1;
        cout<<min(a, b)<<'\n';
        for(int i = 1; i <= m; ++i)
        {
            if(flag)
            {
                if(s[i].u > s[i].v)
                    cout<<i<<'\n';
            }
            else
            {
                if(s[i].u < s[i].v)
                    cout<<i<<'\n';
            }
        }
    }
    return 0;
}

 

全部评论

相关推荐

03-05 17:03
已编辑
浙江工商大学 C++
陈好好wy:整体看下来有点空空的感觉,可以把每一段项目经历都再完善一下,然后用小标题的形式写个两到三条,目前看有点太简单了,不太能看出具体在这个项目里做了什么工作。还是要尽量把自己做的工作以量化的形式体现在简历上呢。
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
6395次浏览 61人参与
# 你的实习产出是真实的还是包装的? #
1304次浏览 32人参与
# 巨人网络春招 #
11213次浏览 223人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7077次浏览 37人参与
# 简历第一个项目做什么 #
31329次浏览 315人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186521次浏览 1115人参与
# 米连集团26产品管培生项目 #
4719次浏览 206人参与
# 研究所笔面经互助 #
118787次浏览 577人参与
# 面试紧张时你会有什么表现? #
30416次浏览 188人参与
# 简历中的项目经历要怎么写? #
309572次浏览 4163人参与
# 职能管理面试记录 #
10722次浏览 59人参与
# AI时代,哪些岗位最容易被淘汰 #
62719次浏览 748人参与
# 网易游戏笔试 #
6374次浏览 83人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6993次浏览 154人参与
# 腾讯音乐求职进展汇总 #
160437次浏览 1107人参与
# 从哪些方向判断这个offer值不值得去? #
56712次浏览 357人参与
# 正在春招的你,也参与了去年秋招吗? #
362741次浏览 2632人参与
# 你怎么看待AI面试 #
179417次浏览 1182人参与
# 小红书求职进展汇总 #
226905次浏览 1357人参与
# 你的房租占工资的比例是多少? #
92146次浏览 896人参与
# 校招笔试 #
467654次浏览 2954人参与
# 经纬恒润求职进展汇总 #
155713次浏览 1085人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务