QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497628#3836. So I'll Max Out My Constructive Algorithm SkillsPetroTarnavskyi#WA 0ms3548kbC++201.8kb2024-07-29 15:19:292024-07-29 15:19:30

Judging History

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

  • [2024-07-29 15:19:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-07-29 15:19:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

struct DSU
{
	int n;
	VI p, sz;
	
	void init(int _n)
	{
		n = _n;
		p.resize(n);
		iota(ALL(p), 0);
		sz.assign(n, 1);
	}
	
	int find(int v)
	{
		if (v == p[v])
			return v;
		return p[v] = find(p[v]);
	}
	bool unite(int u, int v)
	{
		u = find(u);
		v = find(v);
		if (u == v)
			return false;
		if (sz[u] > sz[v])
			swap(u, v);
		p[u] = v;
		sz[v] += sz[u];
		return true;
	}
};

const int N = 100'447;
VI g[N];
int p[N];

void dfs(int v, int par)
{
	p[v] = par;
	for (auto to : g[v])
	{
		if (to != par)
			dfs(to, v);
	}
}


void solve()
{
	int n, m;
	cin >> n >> m;
	DSU d;
	d.init(n);
	map<PII, int> mp;
	bool res = false;
	FOR (i, 0, m)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		if (!d.unite(u, v))
		{
			VI ans;
			dfs(u, -1);
			while (v != u)
			{
				int pv = p[v];
				ans.PB(mp[{v, pv}]);
				v = pv;
			}
			ans.PB(i);
			sort(ALL(ans));
			FOR (j, 0, SZ(ans))
			{
				if (j)
					cout << ' ';
				cout << ans[j] + 1;
			}
			cout << '\n';
			res = true;
			FOR (k, i, m)
				cin >> u >> u;
			break;
		}
		mp[{u, v}] = i;
		mp[{v, u}] = i;
		g[u].PB(v);
		g[v].PB(u);
	}
	if (!res)
		cout << -1 << '\n';
	FOR (i, 0, n)
	{
		g[i].clear();
		p[i] = -1;
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3548kb

input:

1
2
4 3
2 1

output:

2

result:

wrong output format Unexpected end of file - int32 expected