QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127178#6634. Central Subsetshielder#WA 1ms11184kbC++201.7kb2023-07-19 13:52:432023-07-19 13:52:46

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-19 13:52:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11184kb
  • [2023-07-19 13:52:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
vector<int> v[N];
int a[N], b[N];
int dis[N];
bool vis[N];
int n, m;
int x, y;
int in[N];
int ed, mxdis;
void bfs(int st){
    for(int i = 1;i <= n;i++){
        vis[i] = 0;
        dis[i] = 0;
    }
    mxdis= 0;
     queue<int> q;
     q.push(st);
     dis[st] = 0;
     vis[st] = 1;
     while(!q.empty()){
        int x = q.front();
        q.pop();
        for(auto y : v[x]){
            if(vis[y]) continue;
            vis[y] = 1;
            dis[y] = dis[x] +1;
            if(dis[y] > mxdis){
                mxdis = dis[y];
                ed = y;
            }
            q.push(y);
        }
     }
}
int main(){
   int tt;
   cin >> tt;
   while(tt--){
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        v[i].clear();
        vis[i] = 0;
        in[i] = 0;
    }
    int k = ceil(sqrt(n));
    for(int i = 1;i <= m;i++){
         cin >>x >> y;
         in[x]++;
         in[y]++;
         v[x].emplace_back(y);
         v[y].emplace_back(x);
    }
    if(n == 1){
        cout << "1\n1\n";
        continue;
    }
      int st=0, dep= 0;
    //  for(int i = 1;i <= n;i++){
    //    if(in[i] > dep){
    //        dep = in[i];
    //        st = i;
    //    }
    //  }
        //bfs(st);
        bfs(1);
        st = ed;
        bfs(st);
        vector<int> ans;
        ans.push_back(st);
        for(int i = 1;i <= n;i++){
            if(dis[i] && dis[i] % (n+1) == 0){
                ans.push_back(i);
            }
        }
        cout <<ans.size() << "\n";
        for(auto x : ans){
            cout <<x << " ";
        }
        cout << "\n";
   }
   return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 11184kb

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:

1
4 
1
5 

result:

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