Assign the task
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
#include"cstdio" #include"vector" #include"cstring" using namespace std; const int MAXN=50005; int task[MAXN]; vector<int> boss[MAXN]; void assign(int em,int tas) { task[em]=tas; for(int i=0;i<boss[em].size();i++) { int sub=boss[em][i]; task[sub]=tas; assign(sub,tas); } } int main() { int T; scanf("%d",&T); for(int cas=1;cas<=T;cas++) { memset(task,-1,sizeof(task)); int n; scanf("%d",&n); for(int i=0;i<=n;i++) { boss[i].clear(); } for(int i=1;i<=n-1;i++) { int u,v; scanf("%d%d",&u,&v); boss[v].push_back(u); } printf("Case #%d:\n",cas); int m; scanf("%d",&m); while(m--) { scanf("%*c"); char op; scanf("%c",&op); if(op==‘C‘) { int em; scanf("%d",&em); printf("%d\n",task[em]); } else { int x,y; scanf("%d%d",&x,&y); assign(x,y); } } } }
原文:http://www.cnblogs.com/program-ccc/p/5126222.html