QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#127472 | #6634. Central Subset | pyrus | WA | 12ms | 14092kb | C++20 | 1.5kb | 2023-07-19 18:32:25 | 2023-07-19 18:32:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
#define Yes cout<<"YES\n"
#define No cout<<"NO\n"
#define all(a) a.begin(),a.end()
#define pb push_back
#define endl '\n'
//#define int ll
const ll mod=1e9+7;const int M=2e5+5;const int N=2e5+5;
int dx[] = {-1, 1, 0, 0};int dy[] = {0, 0, -1, 1};
vector<int> g[N];queue<int> q;
vector<int> tr[N],ans;
int dep[N],vis[N],k;
void dfs(int u,int fa){
if(tr[u].size()==0){
dep[u]=1;
}
for(auto v:tr[u]){
if(v==fa) continue;
dfs(v,u);
dep[u]=max(dep[u],dep[v]+1);
}
if(dep[u]>k){
ans.pb(u);
dep[u]=1;
}
}
void solve()
{
int n,m;cin>>n>>m;
k=ceil(sqrt(n));
ans.clear();
for(int i=1;i<=n;i++){
g[i].clear();
tr[i].clear();
vis[i]=0;
dep[i]=0;
}
for(int i=1;i<=m;i++){
int x,y;cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
q.push(1);
while(q.size()){
int u=q.front();q.pop();
if(vis[u]) continue;
vis[u]=1;
for(auto v:g[u]){
if(vis[v]) continue;
q.push(v);
tr[u].pb(v);
}
}
dfs(1,0);
cout<<ans.size()<<endl;
for(auto v:ans) {
cout<<v<<' ';
}cout<<endl;
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int __;
__=1;
cin>>__;
while(__--)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 14092kb
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: 12ms
memory: 12840kb
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 7 3 1 1 1 2 0 0 2 6 3 0 1 4 2 10 3 0 3 15 10 5 1 3 1 2 1 5 0 3 11 7 3 1 1 0 1 2 0 1 2 1 3 1 4 2 5 1 0 3 11 7 3 1 1 2 5 1 1 1 0 4 16 11 6 1 1 2 1 4 2 7 4 0 1 3 1 2 1 3 3 7 6 1 0 2 8 4 1 1 1 3 1 2 0 2 6 2 1 3 1 3 2 5 1 0 3 13 8 3 1 1 1 3 1 4 0...
result:
wrong answer Integer 0 violates the range [1, 2] (test case 4)