1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 using namespace std; 5 int n,p; 6 class nerve{public: 7 int C,U,lnum,chnum; 8 nerve * next[102]; 9 int w[102],charge[102]; 10 nerve(){ 11 C=U=lnum=chnum=0; 12 next[0]=0; 13 memset(next,NULL,102*4); 14 memset(w,0,102*4); 15 memset(charge,0,102*4); 16 } 17 }nerves[102]; 18 19 void show(){ 20 nerve *t; 21 for(int i=0;i<n;i++){ 22 t=nerves+i; 23 cout<<"nerve "<<i<<":C="<<t->C<<" U="<<t->U<<" "; 24 for(int ii=0;ii<t->chnum;ii++)cout<<t->charge[ii]<<" "; 25 cout<<endl; 26 } 27 } 28 29 int main() { 30 31 cin>>n>>p; 32 for(int i=0;i<n;i++){ 33 cin>>nerves[i].C>>nerves[i].U; 34 } 35 int a,b,c; 36 nerve *tn,*t0; 37 for(int i=0;i<p;i++){ 38 cin>>a>>b>>c;a--;b--; 39 tn=nerves+a; 40 tn->next[tn->lnum]=nerves+b; 41 tn->w[tn->lnum]=c; 42 tn->lnum++; 43 } 44 int flag=1; 45 for(int i=0;i<n;i++){ 46 //计算C 47 tn=nerves+i; 48 int temp=0; 49 for(int ii=0;ii<tn->chnum;ii++){ 50 temp+=tn->charge[ii]; 51 }//总和充能度 52 if(temp> tn->U) 53 tn->C+=temp - tn->U; 54 55 for(int ii=0;ii<tn->lnum && tn->C>0;ii++){ 56 t0=tn->next[ii]; 57 t0->charge[t0->chnum++]=tn->C * tn->w[ii]; 58 }//为下一个充能 59 //cout<<i<<" : ";show();cout<<endl; 60 if(tn->lnum==0 && tn->C>0){flag=0; 61 cout<<i+1<<" "<<tn->C<<endl; 62 } 63 } 64 if(flag)cout<<"NULL"<<endl; 65 66 return 0; 67 }
https://www.luogu.com.cn/problem/P1038