求调试 CF22C #10TLE
查看原帖
求调试 CF22C #10TLE
602171
Ian_NIE楼主2024/4/19 22:10
#include <iostream>
// 火车头略
#define int long long
using namespace std;

int n, m, v;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> m >> v;
    if(m < n - 1 || m > n * (n - 1) / 2) cout << -1 << endl;
    else
    {
        // 先联通
        for(int i = 1; i <= n; i++)
            if(i != v)
                cout << i << ' ' << v << endl;
        m -= n - 1;
        // 再割点
        int pos = n;
        if(pos == v) pos--;
        for(int i = 1; i <= n - 1; i++)
            if(i != pos && i != v)
                for(int j = i + 1; j <= n; j++)
                    if(j != pos && j != v)
                    {
                        cout << i << ' ' << j << endl, m--;
                        if(!m) goto finish;
                    }
       	finish: ;
    }
    
    return 0;
}

谢谢

2024/4/19 22:10
加载中...