QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127538 | #6634. Central Subset | Vriance | WA | 2ms | 8796kb | C++14 | 1.4kb | 2023-07-19 19:26:41 | 2023-07-19 19:26:43 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#include <cctype>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn=200005;
const int INF=0x7f7f7f7f;
inline int read(){
int x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')w=-1;
for(;isdigit(c);x=(x<<3)+(x<<1)+c-'0',c=getchar());
return x*w;
}
inline ll readll(){
ll x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')w=-1;
for(;isdigit(c);x=(x<<3)+(x<<1)+c-'0',c=getchar());
return x*w;
}
int n,m,k;
vector<int>vct[maxn],st;
int dep[maxn];
int fa[maxn],vis[maxn];
int dfs(int u,int f){
dep[u]=dep[f]+1;
int mx=dep[u];
for(int i=0;i<vct[u].size();i++){
int v=vct[u][i];
if(v==f||fa[v])continue;
fa[v]=u;
mx=max(mx,dfs(v,u));
}
if(mx-dep[u]==k){
st.push_back(u);
return 0;
}
return mx;
}
int main(){
int t=read();
for(;t--;){
n=read(),m=read();
k=(int)sqrt(n)*(int)sqrt(n)<n?(sqrt(n)+1):sqrt(n);
for(int i=1;i<=m;i++){
int u=read(),v=read();
vct[u].push_back(v);
vct[v].push_back(u);
}
int mx=dfs(1,0);
if(mx<k)st.push_back(1);
printf("%d \n",st.size());
for(int i=0;i<st.size();i++){
printf("%d ",st[i]);
}
printf("\n");
st.clear();
for(int i=1;i<=n;i++)vct[i].clear(),dep[i]=fa[i]=0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8796kb
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: 2ms
memory: 8760kb
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 11 6 1 1 2 1 1 2 2 1 0 0 3 6 2 1 0 1 4 3 10 3 1 1 1 4 15 9 3 1 2 3 1 2 2 1 1 5 0 4 11 6 1 1 2 1 1 0 2 2 1 1 1 2 2 1 1 3 1 4 3 5 1 1 0 4 11 6 1 1 2 1 1 3 5 1 1 2 1 1 0 4 16 10 4 1 2 2 1 1 4 2 7 4 0 2 3 1 2 2 1 2 3 1 4 7 6 ...
result:
wrong answer Condition failed: "subset.size() == sz" (test case 1)