QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594804#6634. Central SubsetUESTC_DECAYALI#WA 15ms5596kbC++201.6kb2024-09-28 10:28:512024-09-28 10:29:44

Judging History

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

  • [2024-09-28 10:29:44]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5596kb
  • [2024-09-28 10:28:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 2e5+5;
int n, m, dis1[N], dis2[N];
bool vis[N];
vector<int> G[N], nG[N];

void dfs1(int x) {
    vis[x] = true;
    for (auto v : G[x]) {
        if (vis[v]) continue;
        nG[x].push_back(v);
        nG[v].push_back(x);
        dfs1(v); 
    }
}

int dfs2(int x, int f, int dis[]) {
    int res = x;
    for (auto v : nG[x]) {
        if (v==f) continue;
        dis[v] = dis[x] + 1;
        int tmp = dfs2(v, x, dis);
        if (dis[tmp] > dis[res]) res = tmp;
    }
    return res;
}

void solve() {
    cin >> n >> m;
    for (int i=1; i<=n; ++i) G[i].clear(), nG[i].clear(), vis[i]=false, dis1[i]=dis2[i]=-1;
    for (int i=1; i<=m; ++i) {
        int u, v; cin >> u >> v;
        G[u].push_back(v); G[v].push_back(u);
    }
    dfs1(1);
    // puts("111111");
    dis1[1] = 0; int x = dfs2(1, -1, dis1); 
    dis1[x] = 0; int y = dfs2(x, -1, dis1);
    dis2[y] = 0; dfs2(y, -1, dis2);
    // printf("x=%d y=%d\n", x, y);
    // printf("dis1:"); for (int i=1; i<=n; ++i) printf("%d ", dis1[i]); puts("");
    // printf("dis2:"); for (int i=1; i<=n; ++i) printf("%d ", dis2[i]); puts("");

    int sqr = (int)sqrtl(n);
    // printf("sqr=%d\n", sqr);
    if (sqr*sqr < n) ++sqr;

    vector<int> ans;
    for (int i=1; i<=n; ++i) {
        if (dis1[i]+dis2[i]==dis1[y] && dis1[i]%sqr==0) ans.push_back(i);
    }

    cout << ans.size() << '\n';
    for (int x : ans) cout << x << ' '; cout << '\n';
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t; while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 5564kb

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:

4
3 7 11 15 
2
3 6 
2
2 6 
1
2 
1
2 
3
3 6 9 
1
2 
2
4 8 
3
2 10 16 
1
14 
4
5 10 15 20 
2
3 8 
2
2 10 
2
5 16 
1
4 
4
3 7 11 15 
2
3 7 
1
2 
2
2 9 
1
5 
2
2 4 
2
3 8 
2
4 14 
2
5 18 
1
3 
4
3 7 11 15 
2
4 5 
3
1 5 16 
2
1 3 
1
6 
5
1 6 11 16 21 
2
5 11 
2
4 14 
3
3 7 16 
1
4 
2
3 6 
2
2 6 
2
3 7 
3...

result:

wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1294)