QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#127528 | #6634. Central Subset | Vriance | WA | 3ms | 9224kb | C++14 | 1.4kb | 2023-07-19 19:21:49 | 2023-07-19 19:21:52 |
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=1;i<=st.size();i++){
printf("%d ",st[i-1]);
}
printf("\n");
st.clear();
for(int i=1;i<=n;i++)vct[i].clear(),dep[i]=fa[i]=0;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 9224kb
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 2 1 1
result:
wrong answer Condition failed: "subset.size() == sz" (test case 2)