According to Rex's way of thinking, he knew it could be written.
The topic is still well understood, is to find the current employee's recent tasks.
The practice is that you can open up a Tim variable each time an employee gets a ++tim
Then take a look at the most recent task and write a search to
Core code:
while (num! =-1) { num = A[num].leader; if (Ttime < a[num].time) { ans = a[num].work; Ttime = A[num].time; } }
Source Code:
//#pragma COMMENT (linker, "/stack:16777216")//For C + + Compiler#include <stdio.h>#include<iostream>#include<cstring>#include<cmath>#include<stack>#include<queue>#include<vector>#include<algorithm>#definell Long Long#defineMax (b) ((a) > (b))? (a): (b))#defineMin (b) ((a) < (a))? (a): (b))#defineAbs (x) (((x) > 0)? (x): (-(x)))using namespacestd;Const intINF =0x3f3f3f3f;structsc{intWork , leader, time;} a[50001];intMain () {Std::ios::sync_with_stdio (false); intI, J, K, T, N, M, u, V, num, TT, Casenum, ttime; Charcmd; Casenum=0; CIN>>T; while(t--){ intTim =0; for(i =1; I <=50000; ++i) {A[i].work= -1; A[i].time=0; A[i].leader= -1; } CIN>>N; for(i =1; I < n; ++i) {cin>> u >>v; A[u].leader=v; } cout<<"Case #"<< ++casenum <<":"<<Endl; CIN>>m; while(m--) {cin>>cmd; if(cmd = ='C') {cin>>num; Ttime=A[num].time; intAns =a[num].work; while(num! =-1) {num=A[num].leader; if(Ttime <a[num].time) {ans=a[num].work; Ttime=A[num].time; }} cout<< ans <<Endl; } Else{cin>> Num >>tt; A[num].work=tt; A[num].time= ++Tim; } } } return 0;}
HDU 3974 Assign the task simple search