QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135130#6634. Central Subsetwtn135687#WA 36ms6436kbC++141.4kb2023-08-05 11:51:572023-08-05 11:51:58

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 11:51:58]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:6436kb
  • [2023-08-05 11:51:57]
  • 提交

answer

#include<bits/stdc++.h>
#define pll pair<ll, ll>
using namespace std;
typedef long long ll;
#define int ll

const int N = 1e5+10;
const int M = 1e6 + 7;

int n, m, vis[N], mx;
vector<ll> edge[N];
pll in[N];


void init(){
    mx = sqrt(n);
    if (mx * mx < n)mx++;
    for (int i = 1; i <= n; i++)edge[i].clear(), vis[i] = 0, in[i] = {0, i};
}

inline void solve(){
    cin >> n >> m;
    init();
    for (int i = 1, u, v; i <= m; i++){
        cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
        in[u].first++, in[v].first++;
    }
    sort(in + 1, in + 1 + n, greater<pll>());
    queue<pll> q;
    for (int i = 1; i <= mx; i++){
        vis[i] = 1;
        q.push({0, in[i].second});
    }
    while (q.size()){
        pll temp = q.front();
        q.pop();
        ll x = temp.second, dis = temp.first;
        if (dis == mx)continue;
        for (auto i : edge[x]){
            if (vis[i])continue;
            vis[i] = 1;
            q.push({dis + 1, i});
        }
    }
    ll flag = 1;
    for (int i = 1; i <= n; i++){
        if (!vis[i])flag = 0;
    }
    if (flag){
        cout << mx << endl;
        for (int i = 1; i <= mx; i++)cout << in[i].second << " ";
        cout << endl;
    }
    else cout << -1 << endl;
}



signed main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int WTN666=1;cin>>WTN666;
    while(WTN666--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 6136kb

input:

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

output:

2
3 2 
3
4 1 6 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 6436kb

input:

10000
15 14
13 12
5 4
9 8
11 12
15 14
10 9
14 13
2 3
2 1
6 5
10 11
3 4
7 6
8 7
6 5
2 1
2 4
4 6
2 3
3 5
10 9
8 3
9 4
5 6
5 10
3 2
5 4
2 7
1 2
4 3
2 1
2 1
2 1
2 1
9 8
9 8
5 4
1 2
6 5
3 4
3 2
7 8
7 6
2 1
1 2
14 13
3 10
5 6
2 9
11 4
2 3
2 1
8 7
13 6
5 4
5 12
6 7
4 3
7 14
16 15
2 3
2 1
6 10
6 9
6 4
9 11
...

output:

-1
3
2 4 3 
4
5 4 3 2 
2
2 1 
2
2 1 
3
8 7 6 
2
2 1 
-1
4
6 12 4 15 
4
2 16 15 14 
-1
3
4 3 6 
4
5 4 3 2 
-1
3
2 5 4 
-1
3
4 2 3 
2
2 1 
-1
5
2 19 18 17 16 
2
3 2 
3
3 2 6 
-1
-1
3
2 6 5 
-1
3
2 5 3 
-1
2
2 3 
3
2 8 7 
-1
4
8 6 5 3 
-1
-1
3
2 6 5 
3
5 4 3 
3
3 5 4 
-1
5
5 15 14 11 19 
3
2 8 7 
4
11 ...

result:

wrong answer Integer -1 violates the range [1, 4] (test case 1)