QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389906#1819. Cleaning Robotblack_moonrise#WA 0ms4424kbC++141.7kb2024-04-14 21:04:342024-04-14 21:04:34

Judging History

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

  • [2024-04-14 21:04:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4424kb
  • [2024-04-14 21:04:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 155;
const int MAXM = 3e4 + 5;
typedef long long ll;

int n, m, k;
vector <int> a[MAXM];
vector <int> b[MAXN], c[MAXN];
bool s[MAXN][MAXN];
bool vis[MAXM], instack[MAXM];
int fa[MAXM];

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);
		s[x][y] = true;
		s[y][x] = true;
	}
	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 (s[i][j]) {
			if (b[j].size() >= 3) continue;
			if (b[j].size() == 2) {
				for (auto k : b[j])
					if (k != i) a[i * m + j].push_back(j * m + k);
			} else {
				for (auto k : c[j])
					a[i * m + j].push_back(j * m + k);
			}
		} else {
			if (b[j].size() >= 2) continue;
			if (b[j].size() == 1) {
				int k = b[j][0];
				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: 0ms
memory: 4424kb

input:

10 7 1
8 3

output:

7
4
4
8
2
2
6
10

result:

wrong answer expected '2', found '7'