Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int main()
- {
- int graph[51][51];
- int cases;
- int parts;
- int a,b;
- int base;
- int root;
- int prec;
- scanf("%d",&cases);
- int cnt=1;
- int out_i;
- while(cases > 0)
- {
- int out[1010][2];
- out_i=0;
- scanf("%d",&parts);
- for(int i=0;i<51;i++)
- for(int j=0;j<51;j++)
- graph[i][j] = 0;
- for(int k=0;k<parts;k++)
- {
- scanf("%d %d",&a,&b);
- if(k==0)
- {
- base=a;
- root=a;
- }
- graph[a][b]++;
- graph[b][a]++;
- }
- bool solvable = true;
- int counter=0;
- for(int i=0;i<51;i++)
- {
- for(int j=0;j<51;j++)
- {
- if(graph[i][j]!=0)
- {
- counter +=graph[i][j];
- }
- }
- if(counter % 2 != 0)
- solvable = false;
- }
- /*
- for(int i=0;i<51;i++)
- {
- for(int j=0;j<51;j++)
- {
- if(graph[i][j]!=0)
- counter ++;
- }
- if(counter == 0)
- solvable = false;
- }
- */
- printf("Case #%d\n",cnt);
- if(solvable)
- {
- for(int l=0;l<1001;l++)
- {
- for(int i=0;i<51;i++)
- {
- while(graph[base][base]>0)
- {
- out[out_i][0]=base;
- out[out_i][1]=base;
- out_i ++;
- //printf("%d %d\n",base, base);
- graph[base][base] -=2;
- }
- if((graph[base][i])!=0)
- {
- //printf("%d %d\n",base,i);
- out[out_i][0]=base;
- out[out_i][1]=i;
- out_i ++;
- graph[base][i]-=1;
- graph[i][base]-=1;
- //prec=base;
- base=i;
- }
- }
- }
- }
- if(out_i == parts)
- {
- for(int l=0;l<out_i;l++)
- printf("%d %d\n",out[l][0],out[l][1]);
- if(cases >1)
- printf("\n");
- }
- else
- { if(cases >1)
- printf("some beads may be lost\n\n");
- else
- printf("some beads may be lost\n");
- }
- cases --;
- cnt++;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment