QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226339#6642. (1, 2) NimxuxubaobaoWA 0ms9100kbC++171.6kb2023-10-25 20:30:182023-10-25 20:30:18

Judging History

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

  • [2023-10-25 20:30:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9100kb
  • [2023-10-25 20:30:18]
  • 提交

answer

//It's MyGO!!!
//All OK
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(0);cout << fixed << setprecision(6)
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define LNF (1ll << 60)
#define ll long long
#define ull unsighed long long
// #define int long long
// #define mod 998244353
#define mod 1000000007
using namespace std;

const int N = 2e5 + 10;
vector<int> g[N];
int dis[N];
vector<int> ans;
int sz;

int dfs(int u, int fa){
    // cout << u << ' ' << fa << ' ' << dis[u] << ' ' << dis[fa] << endl;
    dis[u] = dis[fa] + 1;
    int maxn = 0;
    for(auto v : g[u]){
        if(v != fa && !dis[v]){
            
            maxn = max(maxn, dfs(v, u) + 1);
        }
    }
    // cout << u << ' ' << maxn  << ' ' << sz << endl;
    if(maxn == sz && u != 1){
        ans.push_back(u);
        return 0;
    }
    return maxn;
}

void solve(){
    int n, m; cin >> n >> m;
    sz = ceil(sqrt(n));
    // cout << sz << endl;
    memset(dis, 0, sizeof dis);
    for(int i = 1; i <= n; i ++)
        g[i].clear();
    ans.clear();

    for(int i = 1; i <= m; i ++){
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ans.push_back(1);
    dfs(1, 0);
    cout << ans.size() << endl;
    for(auto i : ans)
        cout << i << ' ';
    cout << '\n';
    // cout << '\n';
}

signed main(){
    ios;

    // init();
    int _ = 1;
    cin >> _;
    for(int __ = 1; __ <= _; __ ++){
        // cout << "Case #" << __ << ": ";

        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9100kb

input:

3
2
1 2
1
5
4
1 7 2 9

output:

1
1 
1
1 
1
1 

result:

wrong answer 1st lines differ - expected: 'Grundy', found: '1'