QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127519 | #6634. Central Subset | Vriance | WA | 4ms | 10260kb | C++14 | 1.4kb | 2023-07-19 19:18:11 | 2023-07-19 19:18:14 |
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(st.size()<k)
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10168kb
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 2 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 10260kb
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:
3 11 6 1 1 1 1 2 0 0 2 6 2 0 1 4 2 10 3 0 3 15 9 3 1 3 1 2 1 5 0 3 11 6 1 1 1 0 1 2 0 1 2 1 3 1 4 2 5 1 0 3 11 6 1 1 1 2 5 1 1 1 0 3 16 10 4 1 2 1 4 2 7 4 0 1 3 1 2 1 3 3 7 6 1 0 2 8 3 1 1 1 3 1 2 0 2 6 1 1 3 1 3 2 5 1 0 3 13 7 1 1 1 1 3 1 4 0 3...
result:
wrong answer Integer 0 violates the range [1, 2] (test case 4)