QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372163#3315. Eulerian Flight TourPetroTarnavskyiCompile Error//C++204.4kb2024-03-31 00:39:052024-03-31 00:39:06

Judging History

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

  • [2024-03-31 00:39:06]
  • 评测
  • [2024-03-31 00:39:05]
  • 提交

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

const int N = 147;
int n;
int deg[N];
int e[N][N];
int g[N][N];
int ng[N][N];
bool used[N];

bool dfs(int v, int p = -1)
{
	used[v] = true;
	if (p != -1 && (deg[v] & 1))
	{
		return true;
	}
	FOR (i, 0, n)
	{
		if (!used[i] && ng[v][i])
		{
			bool ok = dfs(i, v);
			if (ok)
			{
				e[v][i] ^= 1;
				e[i][v] ^= 1;
				deg[v]++;
				deg[i]++;
				return true;
			}
		}
	}
	return false;
}

void solve()
{
	vector<VI> comps(n);
	FOR (i, 0, n)
	{
		comps[d.find(i)].PB(i);
		//cerr << i << ' ' << d.find(i) << '\n';
	}
	VI odd;
	FOR (i, 0, n)
	{
		auto& c = comps[i];
		sort(ALL(c), [&](int u, int v)
		{
			return (deg[u] & 1) > (deg[v] & 1);
		});
		if (!c.empty() && deg[c[0]] & 1)
			odd.PB(i);
	}
	//cerr << "Odd " << SZ(odd) << '\n';
	vector<PII> ans;
	if (SZ(odd) == 1)
	{
		int j = odd[0];
		int v = -1;
		FOR (i, 0, n)
			if (d.find(i) != j)
				v = i;
		for (auto u : comps[j])
		{
			if (deg[u] & 1)
			{
				d.unite(u, v);
				deg[u]++;
				deg[v]++;
				e[v][u]++;
				e[u][v]++;
			}
		}
	}
	else
	{
		FOR (i, 0, SZ(odd))
		{
			int j = odd[i];
			int v = comps[j][0];
			int idx = odd[(i + 1) % SZ(odd)];
			int k = 1;
			while (k < SZ(comps[idx]) && deg[comps[idx][k]] & 1)
			{
				int u = comps[idx][k]; 
				e[v][u]++;
				e[u][v]++;
				k++;
				deg[v]++;
				de
				g[u]++;
				//cerr << u << ' ' << v << '\n';
			}
			d.unite(comps[j][0], comps[idx][0]);
		}
	}
	//FOR (i, 0, n)
	//	assert(deg[i] % 2 == 0);
	comps.clear();
	comps.resize(n);
	FOR (i, 0, n)
	{
		comps[d.find(i)].PB(i);
	}
	VI idx;
	FOR (i, 0, n)
	{
		if (comps[i].empty())
			continue;
		idx.PB(i);
	}
	if (SZ(idx) > 2)
	{
		FOR (i, 0, SZ(idx))
		{
			int j = (i + 1) % SZ(idx);
			e[comps[idx[i]][0]][comps[idx[j]][0]]++;
			e[comps[idx[j]][0]][comps[idx[i]][0]]++;
		}
	}
	else if (SZ(idx) == 2)
	{
		if (SZ(comps[idx[0]]) >= 2 && SZ(comps[idx[1]]) >= 2) 
		{
			FOR (i, 0, 2)
			{
				FOR (j, 0, 2)
				{
					int u = comps[idx[0]][i];
					int v = comps[idx[1]][j];
					e[u][v]++;
					e[v][u]++;
				}
			}
		}
		else
		{
			if (SZ(comps[idx[0]]) != 1)
				swap(idx[0], idx[1]);
			int u = comps[idx[0]][0];
			int v = -1;
			int w = -1;
			FOR (i, 0, SZ(comps[idx[1]]))
			{
				FOR (j, 0, i)
				{
					int x = comps[idx[1]][i];
					int y = comps[idx[1]][j];
					if (ng[x][y])
						v = x, w = y;
				}
			}
			if (v == -1)
			{
				cout << -1 << '\n';
				return;
			}
			e[u][v] ^= 1;
			e[v][u] ^= 1;
			e[u][w] ^= 1;
			e[v][w] ^= 1;
			e[w][u] ^= 1;
			e[w][v] ^= 1;
		}
	}
	FOR (i, 0, n)
	{
		FOR (j, 0, i)
		{
		//	cerr << i << ' ' << j << ' ' << e[i][j] << '\n';
			if (e[i][j] & 1)
			{
				ans.PB({j, i});
			}
		}
	}
	cout << SZ(ans) << '\n';
	for (auto [u, v] : ans)
		cout << u + 1 << ' ' << v + 1 << '\n';
	
	
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int m;
	cin >> n >> m;
	d.init(n);
	FOR (i, 0, m)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		d.unite(u, v);
		g[u][v] = 1;
		g[v][u] = 1;
		deg[u]++;
		deg[v]++;
	}
	FOR (i, 0, n) FOR (j, 0, n)
	{
		if (i == j)
			continue;
		ng[i][j] = 1 - g[i][j];
	}
	if (d.sz[d.find(0)] != n)
	{
		solve();
		return 0;
	}
	FOR (i, 0, n)
	{
		if (deg[i] & 1)
		{
			if (!dfs(i))
			{
				cout << -1 << '\n';
				return 0;
			}
			fill(used, used + n, false);
		}
	}
	vector<PII> ans;
	FOR (i, 0, n)
	{
		FOR (j, 0, i)
			if (e[i][j] & 1)
				ans.PB({j, i});
	}
	cout << SZ(ans) << '\n';
	for (auto [u, v] : ans)
		cout << u + 1 << ' ' << v + 1 << '\n';
	
	
	return 0;
}


Details

answer.code: In function ‘void solve()’:
answer.code:141:33: error: ‘de’ was not declared in this scope; did you mean ‘e’?
  141 |                                 de
      |                                 ^~
      |                                 e