Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int cnt,t1,t2,n,k,che[500005],mem[500005],topo[500005],a[500005][3];
- char c1;
- void TOPO(int x){
- // printf("%d\n",x);
- if(che[x] || x==0) return ;
- che[x]=1;
- for(int i=0;i<2;i++)
- {
- TOPO(a[x][i]);
- }
- topo[cnt--]=x;
- }
- int main(){
- int i,j;
- scanf("%d%d",&k,&n);
- cnt=n;
- for(i=1;i<=n;i++)
- {
- scanf(" %c%d%d",&c1,&t1,&t2);
- if(c1=='L') a[i][0]=t1,a[i][1]=t2,a[i][2]=0;
- if(c1=='R') a[i][0]=t2,a[i][1]=t1,a[i][2]=1;
- }
- for(i=1;i<=n;i++) TOPO(i);
- // for(i=1;i<=n;i++) printf("Topo[%d]=%d\n",i,topo[i]);
- mem[1]=k;
- for(i=1;i<=n;i++)
- {
- t2=mem[topo[i]]/2;
- t1=mem[topo[i]]-t2;
- mem[a[topo[i]][0]]+=t1;
- mem[a[topo[i]][1]]+=t2;
- }
- for(i=1;i<=n;i++)
- for(i=1;i<=n;i++)
- {
- a[i][2]=(a[i][2]+mem[i])%2;
- if(a[i][2]==0) printf("L");
- if(a[i][2]==1) printf("R");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement