Example #1
0
int main()
{
	while(scanf("%d %d", &n, &m) != EOF)
	{
		init();
		ford();
	}
	return 0;
}
Example #2
0
int main()
{
    freopen("input.txt", "r", stdin);
    while(init())
    {
        if(num == ford()) printf("T-shirts rock!\n");
        else printf("I'd rather not wear a shirt anyway...\n");
    }
    return 0;
}
Example #3
0
int main() {    
    int i, j; // contadores
    int nv; // n de vertices
    int **m; // matriz do grafo
    int **c; // matriz do caminho, marca as arestas percoridas do vertice 0 ate o vertice n
    int u, v; // coordenadas
    int valor; //Valor da aresta
    FILE *arquivo; // arquivo
    arquivo = fopen("grafo.txt","r");
    
    fscanf(arquivo,"%d", &nv);
    m = (int**) malloc(sizeof(int*) * nv); // alocação
    c = (int**) malloc(sizeof(int*) * nv); // alocação
    
    for (i = 0; i < nv; i++) {
        m[i] = (int*) calloc(sizeof(int), nv);
        c[i] = (int*) calloc(sizeof(int), nv);
    }
	
	//Iniciando a matriz
    for (i = 0; i < nv; i++) {
        for (j = 0; j < nv; j++){
				m[i][j] = 0;
				c[i][j] = 0;
			}
    }
	
    while (1) {
        fscanf(arquivo,"%d %d %d", &u, &v, &valor);
        if (u == -1 && v == -1 && valor ==-1) {
            // fim da leitura
            for (i = 0; i < nv; i++) {
                printf("\n%2d :\t", i);
                for (j = 0; j < nv; j++) {
                    printf("%d\t", m[i][j]);
                }
            }
            printf("\n\n");
				ford(nv, m, c);
            return 0;
        } else {
            m[u][v] = valor;
        }
    }
    fclose(arquivo);
}