QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#456222 | #5239. Mędrcy [A] | Liuxizai | 0 | 2ms | 3816kb | C++20 | 3.9kb | 2024-06-27 15:15:48 | 2024-06-27 15:15:48 |
answer
#include <bits/stdc++.h>
#define File(name) freopen(#name".in", "r", stdin); freopen(#name".out", "w", stdout);
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T>
inline T read(){
T n = 0; int f = 1; char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch)){
n = n * 10 + ch - '0';
ch = getchar();
}
return f * n;
}
template<typename T>
void write(T n){
if(n < 0) return putchar('-'), write(-n);
if(n / 10) write(n / 10);
putchar(n % 10 + '0');
}
void input() {}
template<typename Type, typename... Types>
void input(Type &arg, Types &...args){
arg = read<Type>();
input(args...);
}
namespace Main{
const int N = 1005;
int t, n, m, k, cnt[N], tot, x, ans;
bool cho[N], vis[N], leave[N];
vector<int> g[N];
vector<pair<int, int>> vec;
void dfs(int u){
int deg = 0;
vis[u] = true, tot++;
for(int v: g[u]){
if(cho[v]) continue;
deg++;
if(!vis[v]) dfs(v);
}
cnt[deg]++;
vec.emplace_back(u, deg);
if(deg > 2) x = u;
}
void update(int siz){
if(siz < ans){
for(int i = 1; i <= n; i++) leave[i] = cho[i];
ans = siz;
}
else if(siz == ans){
for(int i = 1; i <= n; i++) if(cho[i]) leave[i] = true;
}
}
void solve(){
bool ok = true;
int res = count(cho + 1, cho + n + 1, true);
if(res > k) return;
memset(vis, 0, sizeof(vis));
vector<int> tmp;
for(int i = 1; i <= n; i++){
if(cho[i] || vis[i]) continue;
tot = 0;
dfs(i);
if(tot > 1){
if(cnt[1] + cnt[2] == tot){
if(cnt[2] == tot){
res += (tot + 1) / 2;
for(auto [u, d]: vec) tmp.push_back(u), cho[u] = true;
}
else{
res += tot / 2;
if(tot & 1){
for(int j = 1; j < tot; j += 2){
tmp.push_back(vec[j].first);
cho[vec[j].first] = true;
}
}
else{
for(auto [u, d]: vec) tmp.push_back(u), cho[u] = true;
}
}
}
else ok = false;
}
for(auto [u, d]: vec) cnt[d] = 0;
vec.clear();
if(!ok) break;
}
if(ok) update(res);
for(int x: tmp) cho[x] = false;
tmp.clear();
if(ok) return;
cho[x] = true;
solve();
cho[x] = false;
for(int i: g[x]){
if(!cho[i]) tmp.push_back(i), cho[i] = true;
}
solve();
for(int i: tmp) cho[i] = false;
}
void Main(){
input(t);
while(t--){
for(int i = 1; i <= n; i++) g[i].clear();
input(n, m, k);
for(int i = 0, u, v; i < m; i++){
input(u, v);
g[u].push_back(v), g[v].push_back(u);
}
ans = 1e9;
solve();
if(ans > k) puts("-1");
else{
int c = count(leave + 1, leave + n + 1, true);
write(ans), putchar(' '), write(c), puts("");
for(int i = 1; i <= n; i++){
if(leave[i]) write(i), putchar(' ');
}
puts("");
}
}
return;
}
} // namespace Main
int main(){
#ifdef Liuxizai
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif // Liuxizai
Main::Main();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3736kb
input:
136 9 37 11 2 7 2 5 2 5 6 8 2 4 2 9 4 5 6 8 6 7 3 9 3 6 3 8 1 9 2 9 4 6 2 4 1 4 7 9 7 9 4 7 3 6 4 5 2 7 1 5 6 9 4 9 4 5 2 7 3 9 1 9 2 7 5 7 1 2 2 3 1 8 3 8 1 3 7 1 13 4 6 3 36 2 2 3 2 3 1 2 2 3 1 3 1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 3 1 2 1 3 1 3 1 2 1 3 1 2 1 3 1 2 2 3 1 2 1 3 1 3 2 3 1 3 2 3 2 3 1 2 1 ...
output:
6 6 1 2 3 4 6 7 5 5 1 2 3 4 7 -1 -1 6 6 1 2 3 4 6 7 5 5 1 2 3 4 7 4 4 1 2 3 4 7 8 1 2 3 4 5 7 8 9 7 9 1 2 3 4 5 6 7 8 9 -1 -1 5 6 1 2 3 4 5 6 4 4 1 2 3 4 8 11 1 2 3 4 5 7 8 9 10 11 12 3 3 1 2 3 4 4 1 2 3 4 4 4 1 2 3 4 5 5 1 2 3 4 7 4 4 1 2 3 4 6 7 1 2 3 4 6 7 10 3 3 1 2 3 5 6 1 2 3 ...
result:
wrong answer 3rd lines differ - expected: '1 2', found: '5 5'
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
139 11 16 6 3 4 1 3 5 7 3 6 3 9 7 10 3 8 1 2 4 8 1 11 4 8 4 9 3 6 4 9 5 9 1 6 8 23 11 2 4 4 8 3 6 4 5 1 3 5 7 3 8 2 5 1 6 1 5 5 8 6 7 1 3 3 5 6 7 7 8 6 8 5 8 4 6 4 8 2 3 1 5 2 8 11 31 1 5 11 3 11 5 7 1 9 3 5 3 5 1 2 1 5 5 7 9 10 2 6 2 7 2 9 5 9 1 11 5 8 4 8 5 6 4 10 3 10 2 9 7 11 5 9 2 6 8 9 9 10 8 ...
output:
5 8 1 3 4 5 7 8 9 10 7 8 1 2 3 4 5 6 7 8 -1 -1 9 10 1 2 3 4 5 6 7 8 10 11 7 7 1 2 3 4 5 6 8 6 6 1 2 3 4 5 6 -1 -1 3 3 1 2 3 -1 -1 5 5 1 2 3 4 5 6 6 1 2 3 4 5 6 4 4 1 2 3 4 9 11 1 2 3 4 5 6 7 8 9 10 11 3 3 1 2 3 5 5 1 2 3 4 5 5 5 1 2 3 4 5 3 3 1 2 3 -1 -1 -1 7 7 1 2 3 4 5 6 10 4 4 1 2 ...
result:
wrong answer 3rd lines differ - expected: '5 7', found: '7 8'
Subtask #3:
score: 0
Wrong Answer
Test #25:
score: 0
Wrong Answer
time: 1ms
memory: 3568kb
input:
66 20 51 30 2 4 5 8 19 20 10 11 7 12 1 20 5 13 12 14 13 15 11 14 4 5 9 16 14 15 5 9 6 14 5 6 3 16 9 18 6 8 14 19 7 8 12 15 8 17 11 14 4 9 11 20 2 13 3 18 5 20 11 13 13 18 3 17 15 20 8 13 4 10 1 6 3 5 7 8 12 14 2 20 4 15 3 20 8 9 3 20 2 16 3 10 2 7 5 19 3 8 8 20 7 10 15 58 30 7 15 8 13 3 13 3 8 4 8 1...
output:
13 15 2 3 4 5 6 7 8 11 12 13 14 15 18 19 20 12 14 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 10 2 3 4 5 6 7 8 10 11 13 10 11 1 2 3 4 5 6 7 8 9 10 11 14 15 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 12 12 1 2 3 4 5 6 7 8 9 10 11 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 12 12 1 2 3 4 5 6 7 8 9 10 11 13 ...
result:
wrong answer 1st lines differ - expected: '12 17', found: '13 15'
Subtask #4:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
67 11 28 30 1 7 1 5 4 11 1 2 2 10 9 11 8 9 7 9 4 8 4 9 5 8 5 7 5 8 2 11 8 10 1 3 2 11 5 8 2 4 7 10 8 11 6 11 2 4 2 11 1 6 10 11 8 11 3 8 10 44 30 5 8 1 4 1 4 3 9 1 4 6 7 3 8 6 7 4 8 4 6 1 2 4 7 1 8 1 5 9 10 2 10 7 8 2 8 1 9 1 5 5 10 1 7 4 6 7 10 2 5 4 8 6 8 8 9 7 10 6 10 4 10 3 5 2 9 6 10 4 8 5 10 5...
output:
6 7 1 2 4 7 8 9 11 8 8 1 2 3 4 5 6 8 10 10 11 1 2 3 4 5 6 7 8 9 10 11 12 12 1 2 3 4 5 6 8 10 11 13 17 18 10 10 1 2 3 4 5 6 7 8 10 11 11 13 1 2 3 4 5 6 7 8 9 10 11 12 13 10 11 1 2 3 4 5 6 7 8 9 10 11 9 10 1 2 3 4 5 6 7 8 9 10 10 11 1 2 3 4 5 6 7 8 9 10 11 12 14 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
result:
wrong answer 1st lines differ - expected: '6 8', found: '6 7'
Subtask #5:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
64 16 32 30 8 13 8 11 5 12 3 10 3 8 6 15 12 13 5 7 1 2 8 14 2 4 8 16 14 15 3 13 6 9 1 11 4 8 15 16 9 12 10 16 4 8 4 5 3 6 3 15 6 14 5 11 3 11 1 15 4 15 6 13 8 14 7 13 15 42 30 1 4 5 13 12 13 9 12 4 9 10 11 9 11 5 6 2 6 3 11 5 14 8 11 4 7 1 15 6 14 2 14 4 11 1 5 6 8 1 7 1 5 9 14 7 15 7 8 5 7 3 9 12 1...
output:
10 14 1 3 4 5 6 8 9 10 11 12 13 14 15 16 10 11 1 2 3 4 5 6 7 9 11 13 14 9 11 1 2 3 4 5 6 7 8 9 10 11 10 11 1 2 3 4 5 6 7 8 9 10 11 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 15 13 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 13 13 1 2 3 4 5 6 7 8 9 10 12 13 15 14 16 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 ...
result:
wrong answer 1st lines differ - expected: '9 10', found: '10 14'
Subtask #6:
score: 0
Wrong Answer
Test #58:
score: 0
Wrong Answer
time: 0ms
memory: 3428kb
input:
32 23 77 30 4 18 1 20 11 20 6 22 7 18 2 17 10 14 3 6 15 22 3 13 14 17 4 16 14 23 1 10 9 14 6 20 4 9 11 16 20 22 5 13 3 23 8 20 2 16 12 16 5 20 1 19 3 8 9 17 15 21 18 23 1 6 3 16 2 6 16 22 16 22 6 15 14 21 4 22 12 19 10 21 2 18 1 10 15 22 7 20 6 19 13 22 5 16 7 22 21 23 14 15 5 16 11 20 10 16 18 19 5...
output:
17 19 1 2 3 4 5 6 7 8 9 10 11 12 14 16 18 19 21 22 23 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 21 29 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 28 30 32 33 34 35 36 37 25 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 26 28 1 2 3 4 ...
result:
wrong answer 1st lines differ - expected: '13 14', found: '17 19'
Subtask #7:
score: 0
Wrong Answer
Test #78:
score: 0
Wrong Answer
time: 0ms
memory: 3448kb
input:
36 20 64 30 5 6 7 14 14 18 13 17 15 16 15 18 2 13 6 20 3 8 10 16 10 20 12 14 15 17 3 4 3 11 6 12 8 11 11 14 8 16 12 20 3 4 18 20 9 12 16 20 11 17 4 7 2 9 12 18 18 20 3 15 12 17 1 7 3 11 1 16 12 20 1 6 8 20 10 19 10 15 14 18 14 18 3 16 3 7 12 19 2 17 4 11 12 20 1 12 5 8 10 17 18 19 12 19 3 17 11 19 3...
output:
13 13 1 2 3 6 7 8 10 11 12 14 16 17 18 21 25 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 19 20 21 22 24 25 26 27 28 29 21 22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 28 34 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 38 26 28 1 2 3 4 5 6 7 8...
result:
wrong answer 1st lines differ - expected: '12 15', found: '13 13'
Subtask #8:
score: 0
Wrong Answer
Test #97:
score: 1
Accepted
time: 2ms
memory: 3716kb
input:
1 1000 3000 30 82 508 127 347 370 658 350 586 486 863 28 99 293 422 427 710 731 936 555 856 91 374 133 676 351 806 780 992 132 686 73 813 212 971 161 919 402 666 59 106 682 766 288 570 199 882 332 428 633 693 306 694 319 882 356 582 546 916 305 665 336 534 608 901 222 228 422 860 406 869 457 524 114...
output:
-1
result:
ok single line: '-1'
Test #98:
score: -1
Wrong Answer
time: 2ms
memory: 3580kb
input:
1 1000 3000 30 266 447 201 576 363 986 110 318 382 520 182 339 5 235 676 781 736 919 396 814 265 779 677 862 67 354 154 603 440 751 642 911 422 642 23 154 110 861 167 400 316 619 778 789 461 668 621 677 339 419 154 248 354 550 398 701 73 940 461 829 547 923 643 986 339 985 110 901 96 461 560 856 552...
output:
-1
result:
wrong answer 1st lines differ - expected: '30 30', found: '-1'
Subtask #9:
score: 0
Wrong Answer
Test #109:
score: 1
Accepted
time: 2ms
memory: 3720kb
input:
1 1000 3000 30 126 407 55 812 361 478 617 796 500 641 338 450 587 739 1 159 753 795 521 995 313 981 35 595 364 914 334 672 615 802 466 789 262 852 258 867 475 686 543 902 334 795 470 899 146 823 713 850 305 574 201 332 119 298 387 747 187 999 95 981 349 731 749 883 829 895 380 818 568 856 738 981 69...
output:
-1
result:
ok single line: '-1'
Test #110:
score: -1
Wrong Answer
time: 0ms
memory: 3652kb
input:
1 1000 3000 30 534 661 174 197 306 990 51 215 197 622 327 560 503 769 462 503 88 327 150 713 77 876 441 755 150 354 14 974 35 281 441 537 501 766 621 657 309 568 234 854 278 657 115 503 162 501 976 990 121 618 441 814 439 854 447 876 197 509 604 925 632 849 281 382 15 319 211 854 258 281 56 501 296 ...
output:
-1
result:
wrong answer 1st lines differ - expected: '30 30', found: '-1'
Subtask #10:
score: 0
Wrong Answer
Test #121:
score: 0
Wrong Answer
time: 1ms
memory: 3816kb
input:
1 1000 3000 30 530 695 780 873 245 704 66 567 435 786 5 536 743 895 374 505 283 773 10 50 250 840 100 416 321 704 390 1000 786 921 374 549 490 626 362 759 661 929 589 704 390 446 123 725 371 447 380 930 10 106 661 876 615 695 410 695 421 695 390 561 10 209 338 780 18 345 41 123 121 773 345 384 558 9...
output:
-1
result:
wrong answer 1st lines differ - expected: '29 29', found: '-1'