TIMESTAMP relay::sync(TIMESTAMP t0) { TIMESTAMP t1 = TS_NEVER; node *f; node *t; set reverse = get_flow(&f,&t); #ifdef SUPPORT_OUTAGES //Handle explicit trips differently if (recloser_event) { //Make sure we aren't locked out if ((recloser_reset_time != 0) && (recloser_reset_time<=t0)) //We're done { //Reset all of the variables recloser_reset_time = 0; recloser_delay_time = 0; current_recloser_tries = 0; status = LS_CLOSED; t1 = TS_NEVER; //Just flag us as something small to continue gl_verbose("Recloser:%d just unlocked and rejoined service",OBJECTHDR(this)->id); } else if ((recloser_reset_time != 0 ) && (recloser_reset_time>t0)) //Not done being locked out { status=LS_OPEN; //Make sure we are still open t1 = recloser_reset_time; } else //Should be normal area { if (status==LS_OPEN) //Open operations - only if a reliability event is occurring { if (recloser_delay_time<=t0) //Time delay has passed - but we are obviously still "in fault" { recloser_tries++; //Increment the tries counter current_recloser_tries++; //Increment the current tries if (current_recloser_tries>recloser_limit) //Now we need to lock out { recloser_delay_time = 0; recloser_reset_time = t0+(TIMESTAMP)(gl_random_exponential(3600)*TS_SECOND); //Figure out how long to lock out gl_verbose("Recloser:%d just reached its limit and locked out for a while",OBJECTHDR(this)->id); t1 = recloser_reset_time; } else //We're still OK to flicker { recloser_delay_time = t0+(TIMESTAMP)(recloser_delay*TS_SECOND); //Get a new time gl_verbose("Recloser:%d just tried to reclose and failed",OBJECTHDR(this)->id); t1 = recloser_delay_time; } } else //still in delay { t1 = recloser_delay_time; } } else //Closed operations - only if a reliability event is occurring { status=LS_OPEN; //Open us up, we are in an event current_recloser_tries = 0; //Reset out count, just in case recloser_reset_time = 0; //Reset the lockout timer, just in case recloser_delay_time = t0+(TIMESTAMP)(recloser_delay*TS_SECOND); //Get a new time gl_verbose("Recloser:%d detected a fault and opened",OBJECTHDR(this)->id); t1 = recloser_delay_time; } } } else //Older method (and catch if reliabilty ends while in lockout) { set trip = (f->is_contact_any() || t->is_contact_any()); //Make sure aren't in overall lockout if ((recloser_reset_time != 0 ) && (recloser_reset_time>=t0)) //We're done being locked out { //Reset all of the variables recloser_reset_time = 0; recloser_delay_time = 0; recloser_tries = 0; status = LS_CLOSED; t1 = TS_NEVER; //Just flag us as something small to continue gl_verbose("Recloser:%d just unlocked and rejoined service",OBJECTHDR(this)->id); } else if ((recloser_reset_time != 0 ) && (recloser_reset_time>t0)) //Not done being locked out { t1 = recloser_reset_time; } else //Should be normal area { /* perform relay operation if any line contact has occurred */ if (status==LS_CLOSED && trip) { status = LS_OPEN; /* schedule recloser operation */ recloser_delay_time=t0+(TIMESTAMP)(recloser_delay*TS_SECOND); gl_verbose("Recloser:%d detected a fault and opened",OBJECTHDR(this)->id); t1 = recloser_delay_time; } /* recloser time has arrived */ else if (status==LS_OPEN && t0>=recloser_delay_time) { /* still have contact */ if (trip) { /* reschedule automatic recloser if retries permits */ if (recloser_limit>recloser_tries) { recloser_tries++; gl_verbose("Recloser:%d just tried to reclose and failed",OBJECTHDR(this)->id); recloser_delay_time = t0+(TIMESTAMP)(recloser_delay*TS_SECOND); t1 = recloser_delay_time; } /* automatic retries exhausted, manual takes an average of an hour */ else { gl_verbose("Recloser:%d just reached its limit and locked out for a while",OBJECTHDR(this)->id); recloser_reset_time = t0+(TIMESTAMP)(gl_random_exponential(3600)*TS_SECOND); t1 = recloser_reset_time; } } else status = LS_CLOSED; } else if ((recloser_delay_time != 0) && (recloser_delay_time>t0)) //Still in delay { t1 = recloser_delay_time; } else //Recover { if (status==LS_OPEN) { gl_verbose("Recloser:%d recovered from a fault",OBJECTHDR(this)->id); } current_recloser_tries = 0; //Reset count variables recloser_tries = 0; status=LS_CLOSED; } } } #endif TIMESTAMP t2=link::sync(t0); return t1<t2?t1:t2; }
int main() { ios_base::sync_with_stdio(0); int TT; cin>>TT; while(TT--) { cin>>N; cin>>s1>>t1>>d1>>s2>>t2>>d2; for(int i=0; i<MAXN; i++) { for(int j=0; j<MAXN; j++) { edge[i][j] = 0; } } for(int i=0; i<N; i++) { string s; cin>>s; for(int j=0; j<N; j++) { if(s[j] == 'X')edge[i][j] = 0; else if(s[j] == 'O')edge[i][j] = 1; else if(s[j] == 'N')edge[i][j] = INF; } } int ans = 0; S = N; T = N + 1; //first for(int i=0; i<MAXN; i++) { for(int j=0; j<MAXN; j++) { cap[i][j] = edge[i][j]; } } cap[S][s1] = cap[t1][T] = d1; cap[S][s2] = cap[t2][T] = d2; ans = get_flow(); //second for(int i=0; i<MAXN; i++) { for(int j=0; j<MAXN; j++) { cap[i][j] = edge[i][j]; } } cap[S][s1] = cap[t1][T] = d1; cap[S][t2] = cap[s2][T] = d2; ans = min(ans, get_flow()); cout<<(ans == d1 + d2 ? "Yes" : "No")<<endl; } return 0; }