Codeforces 1186F - Vus the Cossack and a Graph messing analog / Euler

Question is intended: to give you an undirected graph, the requirements of this operation to erase borders FIG required total number of edges of the graph after Erase> = (/ 2 (n + m)), the degree of each point ceil> = ceil (deg [i] / 2). (Deg [i] where i is the degree of the original)

Ideas 1: Analog fucks +

Direct violence deleted on the line, after reading random side it is difficult to be upset about the hack.

Code:

#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define db double
#define pii pair<int, int>
using namespace std;
const int maxn = 1000010;
struct node {
	you and, v, the;
};
vector<node> G;
int deg[maxn], limit[maxn], a[maxn];
pii b[maxn];
const LL mod = 1e9 + 7;
LL add(LL x, LL y) {return (x + y) % mod;}
LL mul(LL x, LL y) {return (x * y) % mod;}
bool vis[maxn];
bool cmp(int x, int y) {
	return on [x]> provides [y];
}
int main () {
	int n, m, u, v;
	scanf("%d%d", &n, &m);
	tot_limit int = (m + n + 1) / 2;
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &u, &v);
//		G[u].push_back((node){u, v, i});
//		G[v].push_back((node){v, u, i});
		G.push_back((node){u, v, i});
		deg [u] ++;
		provides [v] ++;
	}
	for (int i = 1; i <= n; i++) {
		tours [i] = (deg [i] + 1) / 2;
	}
	random_shuffle(G.begin(), G.end());
	int years = m;
	for (int j = 0; j < G.size() && ans > tot_limit; j++) {
		int v = G[j].v, now = G[j].u;
		if(deg[v] == limit[v]) continue;
		if(deg[now] == limit[now]) continue;
		am [j] = 1;
		years--;
		you [v] -;
		you [now] -;
	}
	printf("%d\n", ans);
	for (int i = 0; i < m; i++) {
		if(vis[i]) continue;
		printf("%d %d\n", G[i].u, G[i].v);
	}
}

Thought 2 (official explanations): New Number 0:00, degree of all points connected to the odd number of the zero point and form a new FIG. Running on the new map again Euler, Euler edge to delete records in the even positions, if it is deleted when the new plus side, directly deleted. Otherwise, look at this edge adjacent to the two sides is not new and can be deleted plus side, if you can, then delete the newly added edge, otherwise delete this edge. That compelling circumstances will delete the original edges.

Code:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
struct edge {
	int u, v, flag;
};

int st[maxn * 2], ans[maxn * 2], re[maxn * 2];
edge a[maxn * 2];
int head[maxn], id[maxn * 4], Next[maxn * 4], ver[maxn * 4], tot, totm, tot_ans;
bool v[maxn * 4], vis[maxn * 4];
int you [Maxnet];
int Top;
void add(int x, int y, int z) {
	ver[++tot] = y, id[tot] = z, Next[tot] = head[x], head[x] = tot;
}
void euler (int s) {
	tot_ans = 0;
	st[++Top] = s;
	while(Top > 0) {
		int x = st[Top], i = head[x];
		while(i && v[i]) i = Next[i];
		if(i) {
			st[++Top] = ver[i];
			re[Top] = id[i];
			v [i] = v [i ^ 1] = 1;
			head[x] = Next[i];
		} else {
			years [tot_ans ++] = re [Top];
			Top--;
		}
	}
}
int main () {
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	to = 1;
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &x, &y);
		totm++;
		a[totm] = (edge){x, y, 1}; 
		add(x, y, totm), add(y, x, totm);
		provides [x] ++, provides [y] ++;
	}
	for (int i = 1; i <= n; i++) {
		if(deg[i] & 1) {
			totm++; 
			a[totm] = (edge){0, i, 0}; 
			add(0, i, totm), add(i, 0, totm);
		}
	}
	int res = m;
	for (int i = 0; i <= n; i++) {
		euler(i);
		for (int j = 2; j <= tot_ans; j + = 2) {
			int now = ans[j];
			if(a[now].flag == 0) vis[now] = 1;
			else {
				int tmp = years [j - 1];
				if(a[tmp].flag == 0 && vis[tmp] == 0) {
					view [tmp] = 1;
					continue;
				}
				int Next = j + 1;
				if(j == tot_ans) Next = 1;
				tmp = ans[Next];
				if(a[tmp].flag == 0 && vis[tmp] == 0) {
					view [tmp] = 1;
					continue;
				}
				vis[now] = 1;
				res--;
			}
		}
	}
	printf("%d\n", res);
	for (int i = 1; i <= totm; i++) {
		if(vis[i] == 0) {
			if(a[i].flag == 1) {
				printf("%d %d\n", a[i].u, a[i].v);
			}
		}
	}
}
//6 6
//3 4
//4 5
//5 3
//1 3
//1 2
//2 3

Guess you like

Origin www.cnblogs.com/pkgunboat/p/11106317.html