1234:ZJTZYRC Screening offer time limit: 5 Sec memory limit: MB
Submissions: 40 Resolution: 10
Label Submission Statistics Discussion edition
Title Description
ZJTZYRC students as the most powerful employment combat, every day will receive a large number of offer. One day ZJTZYRC students decided to filter the offer, just like HR screen resumes. First, the ZJTZYRC students ranked all the offer, from 1 to N in turn. Then, ZJTZYRC students according to various aspects of information, put a certain two offer coinage for the higher ranking. If an offer has the same rank as the others, then the others will be placed in a higher rank. Note that this action does not result in a change in the remaining offer rankings. Occasionally, the ZJTZYRC alumni wanted to know where he had been ranked for an offer, and occasionally wanted to know how many ranking levels were left. Occasionally, the ZJTZYRC Alumni Association, the head of the two of the same level of corporate merger, at this time ignore the operation is OK. input
The first line, an n, indicates how many companies offer. The next n lines, one company name per line, indicate that ZJTZYRC received an offer from the company. Ensure that the company name is unique. The order of the company name corresponds to its initial rank (1~n) of line n+1 a number m, which means that ZJTZYRC students have performed a total of several operations. Next m lines, each line represents an action. The operation is described as follows: "A company name a company name B": ZJTZYRC the two companies merged. "Q Company Name": ZJTZYRC want to know the current rankings of this company. "T": ZJTZYRC want to know how many rankings we have now. We guarantee n<=10000,m<=20000, the company name is a string of uppercase letters beginning with an English character (special characters without any spaces) output
For each q operation, the output line contains an integer representing the current ranking of the company. For each t operation, the output line contains an integer that indicates how many rank levels are currently available. Sample input 5tencenthuaweishanbeibaiduali7ta Baidu Huaweia Shanbei Alia Baidu Aliq tencentq baidut sample Output 5122 Submit a statistical discussion version
and check set and map with, the game when the brain smoked ...
#include <bits/stdc++.h> using namespace std;
typedef long Long LL;
typedef long double LD;
Const double PI = ACOs (-1.0);
int par[10008];
Map<string, int>m;
int find (int u) {if (U = = Par[u]) {return u;
} else {return par[u] = find (Par[u]);
}} void Aunion (int a, int b) {int x = find (a);
int y = find (b);
if (x<y) {par[y] = x;
} else{par[x] = y;
}}///////////////////////////////int main (int argc, CHAR**ARGV) {//ios_base::sync_with_stdio (0); Cin.tie (0);
Freopen ("Input.txt", "R", stdin);
Freopen ("Output.txt", "w", stdout);
int n, m;
CIN >> N;
for (int i = 1; I <= n; i++) {string in;
Cin >> in;
M[in] = i;
} cin >> m;
for (int i = 1; I <= n; i++) {par[i] = i;
} while (m--) {char sw[3];scanf ("%s", SW);
if (sw[0] = = ' t ') {int ans = 0;
for (int i = 1; I <= n; i++) {if (find (i) = = i) {ans++;
}} printf ("%d\n", ans);
} if (sw[0] = = ' a ') {string fr;
String SE;
Cin >> fr >> se;
int u = M[FR];
int v = m[se];
Aunion (U, v);
} if (sw[0] = = ' Q ') {string in;
Cin >> in;
int u = m[in];
int ans = find (u);
printf ("%d\n", ans);
}}//////////////////////////////system ("pause");
return 0; }//end/************************************************************** problem:1234 user:2015217298 Langu age:c++ Result: Correct time:4469 ms memory:2608 KB ****************************************************************/