Cod sursa(job #82759)

Utilizator MariusMarius Stroe Marius Data 8 septembrie 2007 23:44:37
Problema Count Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <stdio.h>

const char iname[] = "count.in";
const char oname[] = "c:\\output.txt";

#define MAXN  30007

unsigned char *G[MAXN][64];


void add_edge(const int x, const int y)
{
	if (G[x][y >> 9] == 0) {
		G[x][y >> 9] = new unsigned char[64];
		for (int i = 0; i < 64; ++ i)
			G[x][y >> 9][i] = 0;
	}
	G[x][y >> 9][(y >> 3) & 63] |= 1 << (y & 7);
}

int query_edge(const int x, const int y)
{
	if (G[x][y >> 9] == 0)
		return 0;
	return (G[x][y >> 9][(y >> 3) & 63] | 1 << (y & 7)) ? 1 : 0;
}

int main(void)
{
	int n;
	int n_edges;
	int x, y;

	FILE *fi = fopen(iname, "r");

	fscanf(fi, "%d", &n);
	fscanf(fi, "%d", &n_edges);
	for (int i = 0; i < n_edges; ++ i) {
		fscanf(fi, "%d %d", &x, &y);
		add_edge(x, y);
		add_edge(y, x);
	}
	fclose(fi);
	printf("%d\n", query_edge(1, 4));

	return 0;
}