Nu aveti permisiuni pentru a descarca fisierul grader_test12.ok
Cod sursa(job #82783)
Utilizator | Data | 9 septembrie 2007 00:48:23 | |
---|---|---|---|
Problema | Count | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.2 kb |
#include <stdio.h>
#include <memory.h>
const char iname[] = "count.in";
const char oname[] = "c:\\output.txt";
#define MAXN 30007
volatile char buf[500000], *pbuf;
const char byte[8] = {1, 2, 4, 8, 16, 32, 64, 128};
unsigned char *G[MAXN][64];
volatile unsigned char globalMemory[13000000];
int globalMemoryPointer;
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;
}
inline 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;
}