QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113481#6634. Central SubsetdnialhWA 29ms10548kbC++142.0kb2023-06-18 07:09:432023-06-18 07:09:47

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:09:47]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:10548kb
  • [2023-06-18 07:09:43]
  • 提交

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);
            }
        }

        if (used.size() > rt){
          cout << n << " " << m << endl;
          FOR(i, 1, n){
            for(int j : e[i]){
              if (i < j)
              cout << i << " " << j << endl;
            }
          }
        }

        if (t <= 10){
        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: 10528kb

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
Wrong Answer
time: 29ms
memory: 10548kb

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:

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

result:

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