QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#132749#6634. Central SubsetRabeya#WA 10ms8380kbC++141.2kb2023-07-31 14:10:322023-07-31 14:10:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-31 14:10:35]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:8380kb
  • [2023-07-31 14:10:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long

const int N = 2e5 + 5;

int n, m, rootN, added;
vector<int> adj[N];
bool vis[N];

void dfs(int u) {
    for(int v: adj[u]) {
        if(vis[v]) continue;
        vis[v] = 1;
        added++;
        if(added >= rootN) return;
        dfs(v);
    }
}

int root(int n) {
    int ret = sqrt(n);
    while(ret*ret < n) ret++;
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int t;
    cin>> t;
    while(t--) {
        cin>> n >> m;
        for(int i=0; i<m; i++) {
            int u, v;
            cin>> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        rootN = root(n);
        vector<int> ans;
        for(int i=1; i<=n; i++) {
            if(vis[i]) continue;
            vis[i] = 1;
            ans.push_back(i);
            added = 0;
            dfs(i);
        }
        cout<< ans.size() << endl;
        for(int e: ans) cout<< e << " "; cout<< endl;
        for(int i=0; i<=n; i++) {
            adj[i].clear();
            vis[i] = 0;
        }
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 8264kb

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
1 4 
2
1 5 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 8380kb

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:

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

result:

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