QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#556165 | #2833. Hamilton | ucup-team1198# | AC ✓ | 32ms | 36060kb | C++20 | 1.9kb | 2024-09-10 15:30:58 | 2024-09-10 15:30:58 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int MAXN = 2e3 + 100;
vector<int> g[MAXN];
int used[MAXN];
vector<int> path;
int c0, c2;
bool dfs(int v) {
path.push_back(v);
used[v] = 1;
--c0;
if (c0 == c2) return true;
for (int u : g[v]) {
if (!used[u]) {
if (dfs(u)) return true;
}
}
path.pop_back();
used[v] = 2;
++c2;
if (c0 == c2) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
while (cin >> n) {
for (int i = 0; i < n; ++i) {
g[i].clear();
}
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
for (int j = 0; j < n; ++j) {
if (s[j] == '1' && i != j) {
g[i].push_back(j);
g[j].push_back(i);
}
}
}
fill(used, used + n, 0);
c0 = n; c2 = 0;
path.clear();
for (int i = 0; i < n; ++i) {
if (!used[i] && dfs(i)) break;
}
vector<int> A, B;
for (int i = 0; i < n; ++i) {
if (used[i] == 0) {
A.push_back(i);
} else if (used[i] == 2) {
B.push_back(i);
}
}
for (int i = 0; i < (int)A.size(); ++i) {
path.push_back(A[i]);
path.push_back(B[i]);
}
bool has_last = false;
for (int u : g[path[0]]) {
if (u == path.back()) {
has_last = true;
}
}
if (has_last) {
vector<int> p;
p.push_back(path.back());
for (int i = 0; i < n - 1; ++i) {
p.push_back(path[i]);
}
path = p;
}
for (int x : path) {
cout << x + 1 << " ";
}
cout << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
3 1 2 3 1 4 2
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
2 3 1 2 1 3 2 1 3 3 1 2
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
4 0000 0000 0000 0000 4 0000 0001 0000 0100 4 0100 1010 0100 0000 4 0111 1000 1000 1000 4 0010 0011 1101 0110 4 0111 1011 1100 1100 4 0111 1011 1101 1110 4 0000 0011 0101 0110 4 0101 1010 0100 1000 4 0011 0011 1100 1100 4 0010 0001 1000 0100
output:
3 1 4 2 2 4 3 1 1 2 4 3 2 1 3 4 1 3 2 4 3 1 2 4 4 1 2 3 2 3 4 1 1 2 4 3 4 1 3 2 2 1 4 3
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
5 00000 00000 00000 00000 00000 5 00001 00000 00000 00000 10000 5 00010 00010 00000 11000 00000 5 00000 00001 00001 00001 01110 5 00001 00001 00001 00001 11110 5 00101 00100 11011 00100 10100 5 01111 10011 10000 11000 11000 5 00011 00011 00011 11101 11110 5 01101 10111 11001 01001 11110 5 00111 0011...
output:
3 4 1 5 2 2 3 1 4 5 4 1 3 2 5 2 5 3 4 1 1 5 3 4 2 1 3 4 5 2 4 1 2 5 3 1 4 2 5 3 1 2 3 5 4 5 1 3 2 4 5 1 2 3 4 5 1 2 4 3 3 1 2 4 5 1 2 4 3 5 5 1 3 2 4 2 3 4 5 1 4 1 2 3 5 5 1 2 3 4 1 3 4 5 2 4 1 3 2 5 1 4 5 2 3 5 1 4 2 3 1 3 2 4 5 1 3 5 2 4 1 2 5 4 3 1 2 3 5 4 2 4 5 3 1 5 1...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
6 000000 000000 000000 000000 000000 000000 6 000000 000000 000001 000000 000000 001000 6 010000 100100 000000 010000 000000 000000 6 000100 000000 000100 101010 000100 000000 6 000100 000000 000100 101011 000100 000100 6 001000 001000 110111 001000 001000 001000 6 001100 000100 100100 111011 000100...
output:
4 1 5 2 6 3 3 6 4 1 5 2 3 1 5 2 6 4 1 4 2 3 6 5 1 4 2 3 6 5 1 3 5 2 6 4 1 3 4 5 6 2 1 4 3 5 6 2 1 2 3 5 6 4 1 3 2 5 6 4 1 3 2 4 5 6 1 2 3 4 5 6 1 2 3 4 6 5 5 1 2 3 4 6 6 1 2 3 4 5 6 1 2 3 4 5 6 1 5 2 3 4 4 1 2 3 5 6 6 1 3 2 4 5 5 1 2 4 3 6 4 1 2 3 5 6 6 1 2 3 5 4 1 2 3 5 6 4 6...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
7 0000010 0001011 0001010 0110100 0001001 1110001 0100110 7 0101001 1011000 0101100 1110010 0010010 0001100 1000000 7 0001111 0011001 0100100 1100101 1011000 1000000 1101000 7 0111111 1011101 1101001 1110010 1100010 1001101 1110010 7 0010111 0010001 1101010 0010000 1000011 1010100 1100100 7 0001010 ...
output:
1 6 2 4 5 7 3 1 2 3 4 6 7 5 5 1 4 2 6 3 7 5 1 2 3 4 6 7 6 1 3 2 7 5 4 1 4 2 3 6 7 5 7 1 5 2 3 4 6 1 5 3 2 4 7 6 4 1 3 5 6 2 7 7 1 4 2 3 6 5 1 4 3 2 5 7 6 5 1 2 3 6 4 7 1 3 2 6 4 7 5 6 1 3 5 7 4 2 2 1 3 4 5 6 7 1 2 3 6 4 7 5 1 2 6 5 3 4 7 5 1 2 4 3 7 6 5 1 3 2 4 6 7 7 1 3 2 4 5 6 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
5 01000 10100 01010 00100 00000 9 001101110 001010001 110100110 101010000 010100011 100000000 101000000 101010001 010010010 4 0000 0011 0101 0110 8 00100101 00101100 11000011 00001111 01010101 11011000 00110000 10111000 9 000000001 001101000 010000100 010000111 000000000 010000111 001101010 00010110...
output:
1 2 3 5 4 1 3 2 5 8 6 4 7 9 2 3 4 1 6 1 3 2 5 4 7 8 1 9 4 2 3 7 6 5 8 4 1 3 2 5 1 4 2 3 6 1 2 3 4 6 5 1 2 3 6 7 4 5 1 3 2 4 7 5 6 8 1 2 3 4 7 6 9 5 10 1 3 4 5 8 2 6 7 9 10 5 1 2 3 6 4 6 1 3 4 2 5 7 8 8 1 3 4 2 5 7 6 9 1 3 2 3 1 2 2 1 4 6 3 5 1 2 3 7 4 6 5 2 1 3 1 3 2 3 1 2 5 4 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
10 0010001000 0010011001 1101101001 0010111000 0011000110 0101001100 1111010001 0000110011 0000100101 0110001110 10 0000000010 0000001001 0000001101 0000100000 0001010111 0000101011 0110010100 0010101000 1000110000 0110110000 10 0110010111 1011111110 1100101010 0100001101 0110001111 1100001010 01111...
output:
7 1 3 2 6 4 5 8 9 10 1 9 5 6 7 2 10 3 8 4 6 1 2 3 5 7 4 8 10 9 9 1 4 2 5 6 3 10 7 8 1 3 2 4 7 8 9 5 10 6 10 1 2 5 3 6 4 8 7 9 1 2 5 3 6 9 8 4 10 7 7 1 4 5 3 2 6 8 9 10 7 1 5 2 3 6 9 10 4 8 1 2 3 5 4 9 6 8 7 10 10 1 2 5 6 4 7 3 9 8 9 1 3 7 2 5 6 8 4 10 10 1 3 4 5 2 6 9 7 8 7 1 2 3 4 6 10...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
10 0110101100 1010100111 1101100101 0010111010 1111001010 0001000000 1001100111 1110001001 0101101000 0110001100 10 0111110111 1001111100 1001100100 1110101111 1111001010 1100001000 0101110100 1111001010 1001100100 1001000000 10 0100000111 1011111001 0100001111 0100100110 0101011100 0100100110 01101...
output:
1 2 3 4 5 7 6 8 9 10 6 1 2 4 3 5 7 8 9 10 9 1 2 3 7 5 4 8 6 10 4 1 2 3 6 7 5 9 8 10 1 3 2 4 6 7 5 9 8 10 1 2 3 4 5 7 8 9 10 6 8 1 2 3 5 4 7 10 6 9 1 2 4 3 5 6 9 7 8 10 3 1 2 4 5 6 7 8 9 10 10 1 2 6 5 4 9 3 7 8 1 2 3 4 5 6 8 7 9 10 4 1 2 3 5 9 6 8 10 7 1 2 4 5 6 7 3 10 8 9 7 1 3 5 2 4 6 ...
result:
ok 200 cases.
Test #10:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
1 4 3 2 6 5 13 10 7 15 9 8 11 12 14 16 17 18 19 20 18 1 3 2 5 7 4 6 8 11 10 12 15 9 13 14 16 17 19 21 1 2 4 5 12 3 7 9 6 10 8 19 11 14 13 16 15 17 18 20 22 1 3 4 2 8 6 10 7 9 11 5 13 12 1 6 2 4 3 5 10 8 9 7 11 13 12 15 17 16 19 20 14 21 18 22 23 24 26 25 28 29 27 30 21 1 2 4 3 6 9 5 7 10 14 15 ...
result:
ok 72 cases.
Test #11:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
59 01110100011001000100111000110110010001011111001011011101100 10001011111001111100111111100010111011100101001100001000101 10000011101010011100111011000001101110001100001110110101001 10001100100110101001000000101101101110001110111001110001101 010101010101101111110011111000100101111111101001111100111...
output:
1 2 5 4 6 9 3 7 8 10 12 11 14 13 17 15 16 18 20 21 23 27 19 22 24 25 26 31 28 30 33 29 35 34 32 36 38 37 40 46 42 39 44 48 43 45 41 47 53 49 50 52 54 51 56 55 57 58 59 1 2 4 5 6 3 8 10 12 7 13 11 18 9 14 22 17 19 15 20 21 23 24 16 28 25 26 29 32 27 31 33 35 37 30 36 34 38 41 39 40 44 42 45 48 43 46...
result:
ok 29 cases.
Test #12:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
160 0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101 000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...
output:
160 1 3 6 2 5 7 4 8 9 10 13 11 14 16 12 15 17 19 18 20 22 26 23 21 28 24 27 33 25 29 30 31 38 32 34 35 37 40 43 44 36 39 45 41 42 46 47 48 53 55 49 54 50 51 52 61 56 57 58 59 60 62 67 63 65 64 70 71 74 68 73 66 72 76 78 69 75 79 77 81 80 83 82 84 85 86 88 87 89 90 92 91 94 97 93 96 95 98 100 101 102...
result:
ok 14 cases.
Test #13:
score: 0
Accepted
time: 0ms
memory: 4744kb
input:
438 01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...
output:
433 1 2 4 3 5 8 7 9 11 10 12 13 17 15 14 6 16 19 23 18 22 26 25 28 21 30 27 20 31 24 33 29 35 34 32 36 37 38 39 40 42 43 50 44 41 45 48 51 46 47 52 49 53 55 54 56 59 57 58 60 61 64 63 62 65 66 67 69 68 71 70 74 73 72 76 75 80 77 79 78 81 84 86 82 88 83 87 85 92 95 90 89 91 96 94 93 100 101 97 98 99 ...
result:
ok 7 cases.
Test #14:
score: 0
Accepted
time: 15ms
memory: 14580kb
input:
1227 0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...
output:
1221 1 2 3 5 6 7 9 4 8 10 13 14 11 12 20 16 17 15 18 19 21 22 23 26 24 25 27 35 30 33 28 29 32 31 37 39 34 36 46 41 40 38 44 43 47 45 42 52 48 49 55 50 58 51 53 57 54 60 56 59 61 63 62 65 64 69 68 70 66 67 72 71 73 75 74 76 78 81 77 82 80 83 87 84 85 79 88 86 92 90 89 91 93 94 95 96 98 97 99 102 104...
result:
ok 2 cases.
Test #15:
score: 0
Accepted
time: 12ms
memory: 12864kb
input:
1078 0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...
output:
1077 1 2 3 4 6 7 5 8 9 10 12 14 17 11 13 15 16 18 19 23 20 22 29 24 21 28 25 30 27 31 32 33 26 36 34 35 38 42 37 40 47 43 48 39 44 41 46 45 50 49 52 53 51 55 54 57 59 56 60 58 61 62 63 64 65 67 70 69 66 71 72 74 73 75 68 77 80 76 82 78 85 81 83 79 89 84 88 87 91 90 92 86 96 93 100 97 95 103 94 98 10...
result:
ok 2 cases.
Test #16:
score: 0
Accepted
time: 7ms
memory: 15248kb
input:
1310 0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...
output:
1310 1 2 3 5 8 4 6 9 11 13 7 10 12 14 15 17 19 18 20 16 24 22 25 23 31 21 26 30 29 28 34 32 35 27 42 33 40 36 41 37 43 38 39 44 46 47 45 48 50 52 54 49 51 56 53 55 60 58 59 66 61 64 63 57 62 68 69 67 72 65 70 71 74 73 75 80 79 76 77 78 81 83 85 84 82 86 87 88 89 90 93 91 95 92 96 94 98 97 99 102 100...
result:
ok 2 cases.
Test #17:
score: 0
Accepted
time: 19ms
memory: 17008kb
input:
1542 0000100001001001100011001101100001110111010111001110111110011011001000110010001111000000100011101001000100000001111001110100110101101111000011100010000100000111010001010110101110000001000001110100101111100001110010111000111001010111011100100100111011010101001100100101110110011000001011001000011...
output:
1542 1 5 3 4 2 8 7 12 9 10 6 14 11 15 13 16 17 18 21 20 23 25 19 22 24 26 27 28 29 30 32 33 34 35 38 36 31 37 39 42 41 40 43 44 45 48 46 47 51 49 50 54 52 58 55 59 53 60 56 57 61 62 63 65 70 64 66 67 69 73 71 68 76 72 74 79 81 75 77 78 80 82 83 84 85 86 87 89 88 90 91 92 93 94 96 98 95 97 99 100 101...
result:
ok 2 cases.
Test #18:
score: 0
Accepted
time: 32ms
memory: 23680kb
input:
2000 0101010000001001011001110100110110001010001110110101101100010010011100000111001100000000110111011111100001110001111011101101110010100100001001110010001111011110011011010000100001011100000000110011000110010100101010110100001010101001111101011001110011010001100110000110101110000001000101001101010...
output:
1 2 4 3 7 5 9 10 6 8 12 11 13 14 15 16 17 18 20 21 19 23 24 22 26 27 25 30 32 28 34 31 35 29 33 40 38 41 36 37 39 42 43 45 44 46 48 49 47 52 51 53 50 54 56 57 55 59 58 61 62 60 63 65 66 64 69 67 68 71 72 76 73 70 77 75 74 78 79 80 82 81 86 83 85 87 84 90 88 91 93 92 97 89 94 96 98 95 102 100 101 103...
result:
ok 1 cases.
Test #19:
score: 0
Accepted
time: 32ms
memory: 23908kb
input:
2000 0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...
output:
2000 1 2 6 3 9 4 5 11 8 7 12 10 17 13 14 18 16 19 15 20 21 25 24 22 23 29 27 26 28 30 31 33 35 32 34 36 37 38 41 39 43 44 42 49 47 51 45 46 40 48 50 52 54 57 56 53 55 58 59 60 61 64 63 66 65 67 68 69 62 70 71 72 73 75 74 76 77 84 81 78 79 82 80 85 86 89 83 93 88 87 90 91 94 92 95 96 100 97 99 101 10...
result:
ok 1 cases.
Test #20:
score: 0
Accepted
time: 20ms
memory: 23828kb
input:
2000 0110101010100011101110010101000111001011110000101111001110111111100111000101010001110111000110110001010000010101101001011001111111011111111111011111000011100001111110000101100100000110100100100110110010000101101101100100001101100010011100000011110000100100011110111001101001101100110111011101011...
output:
1 2 4 5 6 3 10 9 7 8 11 13 12 15 17 19 18 27 16 14 20 21 23 22 30 24 26 25 28 31 29 32 33 35 36 37 34 39 38 40 41 45 43 44 42 47 48 49 46 51 50 52 53 58 56 54 55 59 57 60 62 61 63 64 66 65 67 68 72 69 73 70 75 76 74 71 77 80 79 78 84 81 83 82 85 87 86 88 90 92 102 91 93 89 94 98 96 95 103 99 107 97 ...
result:
ok 1 cases.
Test #21:
score: 0
Accepted
time: 22ms
memory: 23540kb
input:
2000 0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...
output:
1 2 3 4 6 5 8 7 9 10 12 11 13 15 16 20 17 14 18 21 24 19 22 23 29 26 27 28 30 33 34 25 32 36 35 31 38 37 42 39 40 41 43 45 51 46 44 47 50 48 53 49 54 52 55 56 61 58 60 57 59 62 64 63 66 67 69 65 68 70 71 72 76 73 75 83 74 78 77 79 80 81 82 84 86 88 87 85 90 91 93 89 95 96 92 94 97 98 101 99 100 103 ...
result:
ok 1 cases.
Test #22:
score: 0
Accepted
time: 2ms
memory: 3860kb
input:
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
1001 1 1002 2 1003 3 1004 4 1005 5 1006 6 1007 7 1008 8 1009 9 1010 10 1011 11 1012 12 1013 13 1014 14 1015 15 1016 16 1017 17 1018 18 1019 19 1020 20 1021 21 1022 22 1023 23 1024 24 1025 25 1026 26 1027 27 1028 28 1029 29 1030 30 1031 31 1032 32 1033 33 1034 34 1035 35 1036 36 1037 37 1038 38 1039 ...
result:
ok 1 cases.
Test #23:
score: 0
Accepted
time: 31ms
memory: 36060kb
input:
2000 0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
2000 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
result:
ok 1 cases.