Pagini recente » Cod sursa (job #335840) | Cod sursa (job #2687930) | Cod sursa (job #2187675) | Cod sursa (job #1461884) | Cod sursa (job #82776)
Cod sursa(job #82776)
#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;
}