Cod sursa(job #82776)

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

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

#define MAXN  30007

const char byte[8] = {1, 2, 4, 8, 16, 32, 64, 128};

unsigned char *G[MAXN][64];

volatile unsigned char globalMemory[13000000];

int globalMemoryPointer;

volatile char buf[1 << 20], *pbuf;


inline void add_edge(unsigned char *G[], const int y)
{
	unsigned char *p = G[y >> 9];
	if (p == 0) {
		p = (unsigned char *)(globalMemory + globalMemoryPointer);
		globalMemoryPointer += 64;
	}
	p[(y >> 3) & 63] |= byte[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 < '0'; ++ pbuf) ;
	for (; '0' <= *pbuf; ++ pbuf)
		n = n * 10 + *pbuf - '0';
	return n;
}

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

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

	buf[ fread((char *)buf, 1, sizeof(buf), fi)] = 0, pbuf = buf;
	n = get();
	n_edges = get();
	for (int i = 0; i < n_edges; ++ i) {
		x = get();
		y = get();
		add_edge(G[x], y);
		add_edge(G[y], x);
	}
	fclose(fi);

	return 0;
}