Cod sursa(job #82766)

Utilizator MariusMarius Stroe Marius Data 9 septembrie 2007 00:10:41
Problema Count Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <stdio.h>

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

#define MAXN  30007

unsigned char *G[MAXN][64];

unsigned char globalMemory[13000000];

int globalMemoryPointer;

char buf[256], *pbuf;


void add_edge(const int x, const int y)
{
	if (G[x][y >> 9] == 0) {
		G[x][y >> 9] = (unsigned char *)(globalMemory + globalMemoryPointer);
		globalMemoryPointer += 64;
	}
	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 get(void)
{
	int n = 0;

	for (; *pbuf == ' '; ++ pbuf) ;
	for (; '0' <= *pbuf && *pbuf <= '9'; ++ pbuf)
		n = n * 10 + *pbuf - '0';
	return n;
}

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

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

	fscanf(fi, "%d", &n);
	fscanf(fi, "%d\n", &n_edges);
	for (int i = 0; i < n_edges; ++ i) {
		fgets(buf, 256, fi), pbuf = buf;
		x = get();
		y = get();
		add_edge(x, y);
		add_edge(y, x);
	}
	fclose(fi);

	return 0;
}