QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814241#9875. Don't Detect Cycleucup-team3564#WA 86ms55760kbC++232.6kb2024-12-14 16:15:162024-12-14 16:15:16

Judging History

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

  • [2024-12-14 16:15:16]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:55760kb
  • [2024-12-14 16:15:16]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T &x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T &x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 4010, inf = 1e9;
vector <int> v[N];
int id[N][N];
int n, m, dep[N], p[N], cnt[N], vv[N], vw[N], dfn[N], rdfn[N], pcnt, s[N], fa[N];
void dfs(int x, int fa) {
	::fa[x] = fa;
	dfn[x] = ++pcnt;
	dep[x] = dep[fa] + 1;
	for (int i: v[x])
		if (i != fa) {
			if (!dep[i]) {
				dfs(i, x);
				chkmin(vw[x], min(vv[i], vw[i]));
				s[x] += s[i];
			} else if (dep[i] < dep[x]) {
				p[i] = x, p[x] = i;
				cnt[x]++, cnt[i]++;
				chkmin(vv[x], dep[i]);
				s[::fa[i]]--;
				s[x]++;
			}
		}
	rdfn[x] = pcnt;
}
void zhk() {
	read(n), read(m);
	F(i, 1, n) v[i].clear();
	F(i, 1, m) {
		int x, y; read(x), read(y);
		id[x][y] = id[y][x] = i;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	vector <int> ans;
	auto solve = [&] () -> bool {
		pcnt = 0;
		F(i, 1, n) {
			dep[i] = 0;
			s[i] = 0;
			// p[i] = 0;
			cnt[i] = 0;
			vw[i] = vv[i] = inf;
		}
		F(i, 1, n)
			if (!dep[i]) dfs(i, 0);
		F(i, 1, n)
			for (int j: v[i]) if (dep[i] > dep[j]) {
				if (abs(dep[i] - dep[j]) == 1) {
					if (cnt[i] > 1) continue;
					if (cnt[i] == 1) {
						if (dep[p[i]] > dep[i]) continue;
						if (vw[i] <= dep[p[i]]) continue;
					}
					if (cnt[j] > 1) continue;
					if (cnt[j] == 1) {
						if (!(dfn[i] <= dfn[p[j]] && dfn[p[j]] <= rdfn[i])) continue;
						if (vw[p[j]] <= dep[j]) continue;
					}
					// ans.push_back(id[i][j]);
					// v[i].erase(find(all(v[i]), j));
					// v[j].erase(find(all(v[j]), i));
					// return true;
				} else {
					if (s[i] > 1 || s[j] > 1) continue;
				}
				ans.push_back(id[i][j]);
				v[i].erase(find(all(v[i]), j));
				v[j].erase(find(all(v[j]), i));
				return true;
			}
		return false;
	};
	F(i, 1, m) {
		if (!solve()) {
			puts("-1");
			return;
		}
	}
	reverse(all(ans));
	for (int i: ans) cout << i << ' '; cout << '\n';
}
signed main() {
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

input:

1
4 4
1 2
2 3
3 4
4 2

output:

4 3 1 2 

result:

ok Correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

4
4 5
1 2
2 3
3 4
3 1
1 4
5 3
1 2
2 3
3 4
9 10
3 5
1 8
5 8
4 9
6 7
7 9
1 2
1 4
2 4
4 6
8 10
1 4
3 8
2 5
3 4
1 5
5 8
2 8
5 7
4 5
3 7

output:

-1
3 2 1 
4 2 6 10 8 9 5 3 1 7 
-1

result:

ok Correct

Test #3:

score: -100
Wrong Answer
time: 86ms
memory: 55760kb

input:

50
3214 2907
970 1929
2860 3033
1322 2296
931 1192
861 2505
831 2469
231 2549
1 2306
1765 1842
999 3171
177 2007
1798 1894
827 3180
673 1738
1163 1573
2213 2781
2766 3200
1663 2197
1797 2281
315 2637
442 2689
558 2874
1520 2591
651 1923
1133 2920
1747 2412
1104 1528
313 2487
632 3124
660 2182
1581 2...

output:

2453 2069 945 673 1982 1885 1652 1954 17 2360 696 1626 1786 2767 1397 1253 621 2761 98 90 2283 439 312 479 661 1491 13 2210 1161 1227 750 1206 1330 1940 2724 178 2877 1552 575 1383 1649 2233 2639 1686 972 2355 2367 358 1181 2540 1655 2383 759 1298 223 291 806 824 2719 39 2858 221 1368 1619 2591 2677...

result:

wrong answer Wrong - you detected cycles