B题题解

四章

https://ac.nowcoder.com/acm/contest/6012/A

特判多一点,具体代码有注释

include

include

include

using namespace std;
int n, m;
int a, b;
vector<int>G[101000];
void add(int x, int y) {
G[x].push_back(y);
}</int>

int main() {

cin >> a >> b;
if (a == 0 && b == 0) {
    cout << 3 << " " << 3 << endl;
    cout << 1 << " " << 2 << endl;
    cout << 2 << " " << 3 << endl;
    cout << 3 << " " << 1 << endl;
    return 0;
}
if (a == 0 && b != 0) {//没有割点
    if (a == 0 && b == 1) {
        cout << 2 << " " << 1 << endl;
        cout << 1 << " " << 2 << endl;
        return 0;
    }
    printf("-1\n");
    return 0;
}
if (a < b) {//增加桥
    //开始a个割点,a+1个桥
    n = a + 2;
    m = 0;
    for (int i = 2; i <= n; i++) {//造个链
        add(i, i - 1);
        add(i - 1, i);
        m++;
    }
    int cnt = n - 1;//cnt个桥
    cnt = b - cnt;//还要这么多桥
    int len = n + cnt;
    for (int i = n + 1; i <= len; i++) {
        add(i, n-1);
        add(n-1, i);
        m++;
    }
    n = len;
}
else {//删除桥 a>=b
    n = a + 2;
    m = 0;
    for (int i = 2; i <= n; i++) {
        add(i, i - 1);
        add(i - 1, i);
        m++;
    }
    //链子好了
    int cnt = n - 1;
    cnt = cnt - b;
    int len = n;
    for (int i = 2; i <= n; i++) {//两个边可以把一个桥删除,而且保留割点
        if (cnt <= 0) break;
        len++;
        add(len, i);
        add(i, len);
        add(i - 1, len);
        add(len, i - 1);
        m += 2;
        cnt--;
    }
    n = len;
}


cout << n << " " << m << endl;
for (int i = 1; i <= n; i++) {
    for (int p : G[i]) {
        if (p > i) {
            cout << i << " " << p << endl;
        }
    }
}
return 0;

}

全部评论
手机发的,不知道还能不能修改。。。。
点赞 回复 分享
发布于 2020-06-20 01:01
%%%%%
点赞 回复 分享
发布于 2020-06-20 11:13

相关推荐

评论
2
收藏
分享
牛客网
牛客企业服务