QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113479#6634. Central SubsetdnialhRE 1ms10504kbC++141.8kb2023-06-18 07:06:422023-06-18 07:06:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-18 07:06:44]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:10504kb
  • [2023-06-18 07:06:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define F0R(i,a) for(int i=0; i<a; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define pb push_back
#define f first
#define s second

#define MN 200005
int n, m;
vi e[MN];
pii d[MN];
int p[MN];
bool on[MN];

void dfs(int cn){
    for(auto nn : e[cn]) if(nn != p[cn] && p[nn] == -1){
        p[nn] = cn;
        d[nn].f = d[cn].f+1;
        dfs(nn);
    }
}
int main(){
    memset(p, -1, sizeof p);
    int t;
    cin >> t;
    F0R(summit, t){
        cin >> n >> m;
        int rt = 0;
        while(rt*rt<n) rt++;
        F0R(_, m){
            int u, v;
            cin >> u >> v;
            e[u].pb(v);
            e[v].pb(u);
        }
        FOR(i, 1, n){
            d[i].s = i;
        }
        p[1] = 0; 
        dfs(1);
        sort(d+1, d+n+1);
        vi used;
        for(int i=n; i>=1; i--){
            int cur = d[i].s;
            bool ok = false;
            F0R(_, rt){
                if(on[cur]){ ok = true; break; }
                if(cur==1) break;
                cur = p[cur];
            }
            if(!ok){
                on[cur]=true;
                used.pb(cur);
            }
        }

        assert (used.size() <= rt);

        cout << used.size() << "\n";
        for(auto u : used) cout << u << " ";
        cout << "\n";
        FOR(i, 1, n){
            e[i].clear();
            d[i] = {0, 0};
            p[i] = -1;
            on[i] = false;
        }

        F0R(i, 100){
          assert (e[i].size() == 0);
          assert (d[i].s == 0);
          assert (d[i].f == 0);
          assert (p[i] == -1);
          assert (! on[i]);

        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

ok correct (2 test cases)

Test #2:

score: -100
Dangerous Syscalls

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
11 6 1 
2
1 1 
3
2 2 1 
1
1 
1
1 
3
6 2 1 
1
1 
3
4 4 1 
3
10 3 1 
1
1 
4
15 9 3 1 
2
3 1 
3
2 2 1 
3
5 5 1 
1
1 
3
11 6 1 
3
1 1 1 
1
1 
2
2 1 
1
1 
2
2 1 
2
3 1 
3
4 4 1 
2
5 1 
1
1 
3
11 6 1 
2
1 1 
3
5 5 1 
1
1 
1
1 
4
16 10 4 1 
4
2 2 2 1 
3
4 4 1 
4
7 4 4 1 
1
1 
2
3 1 
3
2 2 1 
3
3 3 1 
3
7...

result: