QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708423 | #6634. Central Subset | kalikari | TL | 374ms | 21372kb | C++17 | 2.8kb | 2024-11-03 22:09:42 | 2024-11-03 22:09:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
/*
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
*/
// #define int long long
#define ld long double
//#define INT __int128
#define eb(x) emplace_back(x)
#define fi first
#define se second
#define sc(x) scanf("%d",&x)
#define SC(x) scanf("%lld",&x)
#define reserve reserve
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<long long, long long> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const ld eps = 1e-12;
const int N = 2e5 + 10, M = N + 10;
int n,m;
std::vector<int> g[N],ng[N];
int anc[N][30],dep[N];
// int ans;
set<PII,greater<PII>>s;
void bfs(){
queue<int>q;
q.push(1);
dep[1]=0;
anc[1][0]=1;
while(!q.empty()){
int t=q.front();
q.pop();
s.insert({dep[t],t});
for(int i=0;i<g[t].size();i++){
int v=g[t][i];
if(dep[v]>dep[t]+1){
dep[v]=dep[t]+1;
anc[v][0]=t;
q.push(v);
}
}
}
}
void del(int u){
s.erase({dep[u],u});
for(int i=0;i<g[u].size();i++){
int v=g[u][i];
if(dep[v]==dep[u]+1){
del(v);
}
}
}
void solve(){
scanf("%d%d",&n,&m);
s.clear();
for(int i=1;i<=n;i++){
g[i].clear();
// ng[i].clear();
dep[i]=inf;
}
for(int i=1;i<=m;i++){
int a,b;
scanf("%d%d",&a,&b);
g[a].emplace_back(b);
g[b].emplace_back(a);
}
bfs();
for(int i=1;i<10;i++){
for(int j=1;j<=n;j++){
anc[j][i]=anc[anc[j][i-1]][i-1];
}
}
// for(int i=1;i<=n;i++){
// for(int j=0;j<10;j++){
// cout<<anc[i][j]<<" ";
// }
// cout<<endl;
// }
// cout<<"============ "<<s.size()<<endl;
int sq=sqrt(n);
if(sq*sq<n){
sq++;
}
// int cn=0;
vector<int>ans;
while(s.size()){
// cn++;
int u=(*s.begin()).second;
// cout<<"+++++++++ ---"<<u<<endl;
for(int i=0;i<10;i++){
if((sq>>i)&1){
u=anc[u][i];
}
}
ans.emplace_back(u);
// cout<<"___________"<<u<<endl;
del(u);
}
printf("%d\n",ans.size());
for(int i=0;i<ans.size();i++){
printf("%d ",ans[i]);
}
printf("\n");
}
signed main(){
// ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1,cas=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
/*
25 24
1 2
2 3
3 4
4 5
5 6
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
6 20
6 21
6 22
6 23
6 24
6 25
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16304kb
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: 0
Accepted
time: 29ms
memory: 14980kb
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 2 2 1 1 1 1 1 3 6 2 1 1 1 2 4 1 3 10 3 1 1 1 4 15 9 3 1 2 3 1 2 2 1 2 5 1 1 1 3 11 6 1 1 1 1 1 2 2 1 1 1 2 2 1 2 3 1 2 4 1 2 5 1 1 1 3 11 6 1 1 1 2 5 1 1 1 1 1 4 16 10 4 1 2 2 1 2 4 1 3 7 4 1 1 1 2 3 1 2 2 1 2 3 1 3 7 6 1 1 1 3 8 3 1 1 1 2 3 1 ...
result:
ok correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 98ms
memory: 17092kb
input:
100 2000 1999 529 528 885 884 1221 1222 375 374 245 244 758 757 711 710 1521 1522 1875 1874 749 750 823 822 1959 1958 1767 1766 155 154 631 632 825 824 1330 1331 457 456 1344 1343 1817 1818 413 414 582 583 1828 1827 1335 1336 654 655 162 161 1668 1667 1966 1967 1472 1471 1185 1184 518 517 1509 1510 ...
output:
44 1955 1909 1863 1817 1771 1725 1679 1633 1587 1541 1495 1449 1403 1357 1311 1265 1219 1173 1127 1081 1035 989 943 897 851 805 759 713 667 621 575 529 483 437 391 345 299 253 207 161 115 69 23 1 1 1 23 956 911 866 821 776 731 686 641 596 551 506 461 416 371 326 281 236 191 146 101 56 11 1 6 1170...
result:
ok correct (100 test cases)
Test #4:
score: 0
Accepted
time: 374ms
memory: 21372kb
input:
10 14914 14913 13959 13958 3643 3642 4582 4581 13378 13379 981 980 12901 12902 12355 12356 14692 14691 9670 9669 14632 14631 1441 1440 1367 1368 6237 6238 8297 8298 1021 1020 5096 5097 4773 4774 7778 7779 3013 3014 5536 5535 11621 11620 13904 13903 3050 3049 14179 14178 7471 7472 13380 13381 7403 74...
output:
121 14791 14667 14543 14419 14295 14171 14047 13923 13799 13675 13551 13427 13303 13179 13055 12931 12807 12683 12559 12435 12311 12187 12063 11939 11815 11691 11567 11443 11319 11195 11071 10947 10823 10699 10575 10451 10327 10203 10079 9955 9831 9707 9583 9459 9335 9211 9087 8963 8839 8715 8591 84...
result:
ok correct (10 test cases)
Test #5:
score: 0
Accepted
time: 97ms
memory: 17940kb
input:
10 20000 19999 6831 6760 15763 15900 10362 10184 5821 5880 17555 17389 16708 16574 11592 11436 186 209 19380 19313 8867 8718 12100 12237 16245 16110 18464 18568 4713 4665 17412 17578 18666 18750 4360 4322 12350 12502 4054 4103 2874 2849 8097 8202 14489 14639 1056 1016 13500 13581 2435 2391 199 173 8...
output:
4 6126 3269 1143 1 5 10809 8283 178 176 1 5 11257 8040 3276 471 1 5 10584 9863 3873 3415 1 6 15169 14623 8672 8665 1487 1 6 15046 6159 4075 2577 207 1 7 15985 8593 6581 1059 972 256 1 6 7843 6192 5415 2418 266 1 6 14312 1588 1088 1025 27 1 5 8901 8799 7775 2515 1
result:
ok correct (10 test cases)
Test #6:
score: -100
Time Limit Exceeded
input:
1 200000 199999 136649 136648 44943 44944 7148 7149 50332 50333 149967 149966 28976 28975 78549 78550 178698 178697 96434 96433 7859 7858 88976 88977 23348 23347 161682 161681 125393 125392 67892 67893 73592 73593 179054 179055 110841 110842 163714 163715 7982 7981 56309 56310 196486 196485 19176 19...