QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389895 | #1819. Cleaning Robot | black_moonrise# | WA | 1ms | 5828kb | C++14 | 1.3kb | 2024-04-14 21:00:36 | 2024-04-14 21:00:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e4 + 5;
typedef long long ll;
int n, m, k;
vector <int> a[MAXN];
vector <int> b[MAXN], c[MAXN];
bool vis[MAXN], instack[MAXN];
int fa[MAXN];
void dfs(int pos) {
vis[pos] = true;
instack[pos] = true;
for (auto x : a[pos])
if (instack[x]) {
vector <int> ans;
ans.push_back(x % n);
int tmp = pos;
while (tmp != x) {
ans.push_back(tmp % n);
tmp = fa[tmp];
}
cout << ans.size() << endl;
for (auto x : ans)
cout << x + 1 << endl;
exit(0);
} else if (!vis[x]) {
fa[x] = pos;
dfs(x);
}
instack[pos] = false;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= k; i++) {
int x, y; scanf("%d%d", &x, &y);
x--, y--;
b[x].push_back(y);
b[y].push_back(x);
}
for (int i = k + 1; i <= m; i++) {
int x, y; scanf("%d%d", &x, &y);
x--, y--;
c[x].push_back(y);
c[y].push_back(x);
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (b[j].size() >= 2) continue;
if (b[j].size() == 1) {
int k = b[j][0];
if (k != i) a[i * m + j].push_back(j * m + k);
} else {
for (auto k : c[j])
if (k != i) a[i * m + j].push_back(j * m + k);
}
}
for (int i = 0; i < n * n; i++)
if (!vis[i]) {
dfs(i);
}
puts("-1");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5828kb
input:
10 7 1 8 3
output:
-1
result:
wrong answer expected '2', found '-1'