Codeforces Round #429 (Div. 2), problem: (D) Leha and another game about graph Solution In C/C++

#include<cstdio>
using namespace std;
const int MAXN = 300000+5;
const int MAXE = MAXN*2;
int to[MAXE], nxt[MAXE], head[MAXN], ne;
void addEdge(int f, int t) {
to[++ne] = t;
nxt[ne] = head[f];
head[f] = ne;
}
int n, m;
int d[MAXN];
bool vis[MAXN];
bool mark[MAXE];
int ednum;
int dfs(int u) {
vis[u] = true;
int tot = (d[u] == 1);
for (int i = head[u]; i; i = nxt[i])
{
if (vis[to[i]]) continue;
int v = to[i];
int tmp = dfs(v);
if (tmp & 1) mark[(i+1)>>1] = true, ednum ++;
tot += tmp;
}
return tot;
}
int main()
{
scanf(“%d%d”, &n, &m);
int num = 0;
for (int i = 1; i<=n; i++)
{
scanf(“%d”, &d[i]);
if (d[i] == 1) num++;
}
bool flag = false;
if (num & 1) {
for (int i = 1; i<=n; i++) {
if (d[i] == -1 && !flag) {
d[i] = 1; flag = true;
}else if (d[i] == -1) d[i] = 0;
}
if (!flag) {
puts(“-1”);
return 0;
}
}else {
for (int i = 1; i<=n; i++) if (d[i] == -1) d[i] = 0;
}
for (int i = 1; i<=m; i++) {
int u, v; scanf(“%d%d”, &u, &v);
addEdge(u, v); addEdge(v, u);
}
dfs(1);
printf(“%d\n”, ednum);
for (int i = 1; i <= m; i++) {
if (mark[i]) printf(“%d\n”, i);
}
return 0;
}

Infected with TDSS and...

Dealing with TDSS Rootkit Infections and Google Search Redirects Computer...

Ronda Rousey vs. Gina...

The Dream Match: Ronda Rousey vs. Gina Carano at...

Why Everyone is Obsessed with the Universal Car Cleaning Gel

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Portable Door Lock for Travel

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Infected with TDSS and Google Keeps redirecting

Dealing with TDSS Rootkit Infections and Google Search Redirects Computer security is a continuous battle, and some threats are significantly more stubborn than others. A...

Why Everyone is Obsessed with the Portable Handheld Misting Fan

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Mini Magnetic Bag Sealer

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Ronda Rousey vs. Gina Carano MVP MMA live blog

The Dream Match: Ronda Rousey vs. Gina Carano at MVP MMA The world of mixed martial arts is currently witnessing a moment many thought would...

Why Everyone is Obsessed with the Electric Spin Scrubber Pro

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Mini Magnetic Bag Sealer

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Electric Spin Scrubber Pro

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...