12th fzu assign the task (violent DFS) in multiple schools)

Source: Internet
Author: User

when I hit this question, I suddenly found that I could not even simulate an array of critical tables. It was a sin and a sin...

# Include <cstdio> # include <cstring> int n, m; const int maxn = 200050; int head [maxn], CNT; struct edge {int V, task, next ;} edge [maxn]; int node [maxn]; void addedge (int v, int U) {edge [CNT]. V = V; edge [CNT]. next = head [u]; head [u] = CNT ++;} void DFS (int u, int task) {int P = head [u]; node [u] = task; (;~ P; P = edge [p]. next) {int v = edge [p]. v; DFS (v, task);} return;} void Init () {memset (Head,-1, sizeof (head); CNT = 0;} void debug () {for (INT I = 0; I <n; ++ I) {printf ("% d", node [I]) ;}printf ("\ n ");} int main () {int CAS; char TMP [5]; int U, V, task; scanf ("% d", & CAS); For (INT I = 1; I <= CAS; ++ I) {scanf ("% d", & N); Init (); memset (node,-1, sizeof (node )); for (INT I = 0; I <n-1; ++ I) {scanf ("% d", & U, & V); addedge (u, v );} scanf ("% d", & M); printf ("case # % d: \ n", I); For (INT I = 0; I <m; ++ I) {scanf ("% s", TMP); If (TMP [0] = 'C') {scanf ("% d", & U ); printf ("% d \ n", node [u]); // debug ();} If (TMP [0] = 'T ') {scanf ("% d", & U, & task); DFS (u, task) ;}} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.