222452026-01-14 18:29:33algoproEgyirányú egyensúlycpp17Accepted 50/5048ms6004 KiB
// UUID: 4bfd80c6-aa7f-47ab-80a7-a6c0dca62059
#include <bits/stdc++.h>
using namespace std;

vector<vector<array<int, 3>>> g;
vector<int> q;
vector<int> w;

void dfs(int h){
	while(w[h] < g[h].size()){
		if(q[g[h][w[h]][1]]!=0){
			w[h]++;
			continue;
		}
		q[g[h][w[h]][1]]=g[h][w[h]][2];
		dfs(g[h][w[h]++][0]);
	}
}

int main() {
	int n , m; cin >> n >> m;
	g.resize(n+1);
	w.resize(n+1);
	int o = 0;
	for(int i = 0; i < m; i++){
		int x , y;cin >> x >> y;
		g[x].push_back({y , o , 1});
		g[y].push_back({x , o , -1});
		o++;
	}
	for(int i = 1; i <= n; i++){
		if(g[i].size()%2){
			g[0].push_back({i , o , 1});
			g[i].push_back({0 , o , -1});
			o++;
		}
	}
	q.resize(o , 0);
	for(int i = 0; i <= n; i++)dfs(i);
	cout << o-m << endl;
	for(int i = 0; i < m; i++)cout << (q[i]==1?"-> ":"<- ");
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/037ms4444 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/22ms316 KiB
11Accepted2/22ms316 KiB
12Accepted2/22ms316 KiB
13Accepted3/38ms1380 KiB
14Accepted3/319ms3124 KiB
15Accepted3/323ms3404 KiB
16Accepted3/325ms2920 KiB
17Accepted3/312ms2108 KiB
18Accepted3/325ms2356 KiB
19Accepted3/327ms3016 KiB
20Accepted3/337ms4748 KiB
21Accepted3/343ms5052 KiB
22Accepted3/348ms6004 KiB