QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389895#1819. Cleaning Robotblack_moonrise#WA 1ms5828kbC++141.3kb2024-04-14 21:00:362024-04-14 21:00:36

Judging History

你现在查看的是最新测评结果

  • [2024-04-14 21:00:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5828kb
  • [2024-04-14 21:00:36]
  • 提交

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;
}

详细

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'