Sicily 1063. Who's the boss

Source: Internet
Author: User


# Include <iostream> # include <cstdio> # include <vector> # include <algorithm> using namespace STD; int n, m, Q, Y, K; struct node {int ID, Sala, height; int boss, child; // sub stores the position of the first-level subordinates. Child records the number of all subordinate vectors <int> sub; bool operator <(const node & O) const // in descending order {return Sala> O. sala; // No two employees have the same salary .}} person [30010]; int main () {int I, j; scanf ("% d", & N); While (n --) {scanf ("% d", & M, & Q); for (I = 0; I <m; ++ I) {scanf ("% d", & person [I]. ID, & person [I]. sala, & person [I]. height); person [I]. sub. clear (); person [I]. child = 0;} Sort (person, person + M); // employees are sorted in descending order of salary (I = s-1; I> = 0; -- I) {for (j = I-1; j> = 0; -- j) // immediate boss makes the least money than you do and the height cannot be lower than you if (person [J]. height> = person [I]. height) break; If (j> = 0) {person [I]. boss = J; person [J]. sub. push_back (I); // I is the first subordinate of J} else person [I]. boss =-1; // boss =-1 indicates no superiors} for (I = s-1; I> = 0; -- I) {If (person [I]. sub. size ()> 0) {for (j = 0; j <person [I]. sub. size (); ++ J) person [I]. child + = person [person [I]. sub [J]. child + 1; // you can know the total number of subordinates} int ID as long as you calculate all the subordinates at the first layer; while (Q --) {scanf ("% d ", & ID); for (I = 0; I <m; ++ I) if (person [I]. id = ID) break; If (person [I]. boss =-1) printf ("0% d \ n", person [I]. child); else printf ("% d \ n", person [person [I]. boss]. ID, person [I]. child) ;}} 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: 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.