Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- typedef struct celula{
- long long int valor;
- int id;
- int prox;
- }celula;
- /* ---------------------------------- */
- int main(void)
- {
- int n;
- celula *vector = calloc(n,sizeof(celula));
- scanf("%d",&n);
- long long int ultimo;
- for(int a = 0; a < n; a++)
- {
- int id,prox;
- long long int valor;
- scanf("%d%lld%d",&id,&valor,&prox);
- if(prox != -1)
- {
- vector[a].prox = prox;
- vector[a].valor = valor;
- vector[a].id = id;
- }else
- ultimo = valor;
- }
- printf("%lld\n",vector[0].valor);
- for(int a = 0; a < n; a++)
- {
- for(int b = a; b < n; b++)
- {
- if(vector[a].prox == vector[b].id && vector[a].id)
- {
- printf("%lld\n",vector[b].valor);
- vector[a].id = vector[b].id = -2;
- }
- }
- }
- printf("%lld\n",ultimo);
- free(vector);
- return 0;
- }
- /* ---------------------------------- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement