Submission #6378458


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;

vector<int> adj[100010];
int color[100010];
pair<int,int> edges[100010];

//0 keluar 1 masuk

void dfs(int u,int col)
{
	color[u] = col;
	if (adj[u].size() % 2 == 1)
		color[u] = 0;
	for (int i = adj[u].size() % 2 ; i < adj[u].size() ; i++)
	{
		if (color[adj[u][i]] == color[u])
		{
			if ((adj[u].size() % 2) == (adj[adj[u][i]].size() % 2))
			{
				cout << -1 << endl;
				exit(0);
			}
		}
		if (color[adj[u][i]] == -1)
			dfs(adj[u][i],1 - color[u]);
	}
	if (adj[u].size() % 2 == 1)
	{
		if (color[adj[u][0]] == 1)
		{
			cout << -1 << endl;
			exit(0);
		}
		if (color[adj[u][0]] == -1)
			dfs(adj[u][0],0);
	}
}

map< pair<int,int>,bool > sudah;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin >> n >> m;
	for (int i = 1 ; i <= m ; i++)
	{
		int ta,maudy;
		cin >> ta >> maudy;
		adj[ta].push_back(maudy);
		adj[maudy].push_back(ta);
		edges[i] = {ta,maudy};
	}
	for (int i = 1 ; i <= n ; i++) if (adj[i].size() % 2 == 1)
	{
		for (int j = 0 ; j < adj[i].size() ; j++)
		{
			if (adj[adj[i][j]].size() % 2 == 1)
			{
				cout << -1 << endl;
				return 0;
			}
		}
	}
	memset(color,-1,sizeof(color));
	bool ada = 0;
	for (int i = 1 ; i <= n ; i++)
	{
		if (adj[i].size() % 2 == 1)
		{
			dfs(i,0);
			ada = 1;
			break;
		}
	}
	if (!ada)
		dfs(1,0);
	for (int i = 1 ; i <= n ; i++)
	{
		for (int j = 0 ; j < adj[i].size() ; j++)
		{
			if (sudah[{i,adj[i][j]}] || sudah[{adj[i][j],i}]) continue;
			sudah[{i,adj[i][j]}] = sudah[{adj[i][j],i}] = 1;
			if (adj[i].size() % 2 == 1)
			{
				if (j == 0)
					cout << adj[i][j] << " " << i << endl;
				else
					cout << i << " " << adj[i][j] << endl;
			}
			else
			{
				if (color[i] == 0)
					cout << i << " " << adj[i][j] << endl;
				else
					cout << adj[i][j] << " " << i << endl;		
			}
		}
	}
}

Submission Info

Submission Time
Task B - Even Degrees
User akumahappanatuh
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2067 Byte
Status WA
Exec Time 315 ms
Memory 26752 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 14
WA × 22
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt WA 33 ms 6528 KB
02.txt WA 33 ms 6528 KB
03.txt WA 33 ms 6528 KB
04.txt WA 33 ms 6528 KB
05.txt AC 34 ms 6528 KB
06.txt WA 31 ms 5504 KB
07.txt WA 31 ms 5504 KB
08.txt WA 31 ms 5504 KB
09.txt WA 31 ms 5504 KB
10.txt AC 32 ms 5504 KB
11.txt WA 25 ms 4864 KB
12.txt WA 25 ms 4864 KB
13.txt WA 25 ms 4864 KB
14.txt WA 25 ms 4864 KB
15.txt AC 25 ms 4864 KB
16.txt WA 21 ms 4480 KB
17.txt WA 21 ms 4480 KB
18.txt WA 21 ms 4480 KB
19.txt WA 21 ms 4480 KB
20.txt AC 21 ms 4480 KB
21.txt WA 17 ms 4480 KB
22.txt WA 17 ms 4480 KB
23.txt WA 17 ms 4480 KB
24.txt WA 17 ms 4480 KB
25.txt AC 17 ms 4480 KB
26.txt AC 37 ms 13184 KB
27.txt AC 36 ms 13184 KB
28.txt AC 315 ms 26752 KB
29.txt AC 309 ms 26752 KB
30.txt WA 2 ms 2560 KB
31.txt AC 2 ms 2560 KB
32.txt AC 2 ms 2944 KB
33.txt AC 2 ms 2944 KB
34.txt WA 2 ms 2560 KB
s1.txt AC 2 ms 2944 KB
s2.txt AC 2 ms 2560 KB