#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#include<ctime>
using namespace std;
typedef long long i64;
#define SS(a) scanf("%d",&a)
#define MM(name,what) memset(name,what,sizeof(name))
#define MC(a,b) memcpy(a,b,sizeof(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 222;
struct Grade{
int a;
int b;
bool operator < (const Grade &cmp) const{
return a < cmp.a;
}
};
int n;
int m[maxn];
char c[maxn];
Grade grade[maxn];
vector<int>g[maxn];
vector<Grade>choice[maxn];
bool vis[maxn];
Grade dp[maxn];
void find(int now){
if (vis[now]) return;
int to;
for (int i = 0; i < (int)g[now].size(); i++){
to = g[now][i];
if (!vis[to]){
find(to);
}
}
if (c[now] == 'X'){
for (int x = 0; x <(int) g[now].size(); x++){
to = g[now][x];
for (int i = 0; i <(int) choice[to].size(); i++){
choice[now].push_back(choice[to][i]);
}
}
}
else if(c[now] == 'A'){
if (m[now] == 1){
to = g[now][0];
for (int i = 0; i < choice[to].size(); i++){
choice[now].push_back(choice[to][i]);
}
}
else{
int temp;
for (int x = 0; x < (int)g[now].size(); x++){
temp = -1;
for (int i = 0; i < (int)g[now].size(); i++){
if (i == x) continue;
to = g[now][i];
if (choice[to][0].a > temp){
temp = choice[to][0].a;
}
}
to = g[now][x];
for (int i = 0; i < (int)choice[to].size(); i++){
if (choice[to][i].a>=temp){
choice[now].push_back(choice[to][i]);
}
}
}
}
}
sort(choice[now].begin(), choice[now].end());
vis[now] = true;
}
void dfs(int now){
int to;
for (int i = 0; i <(int) g[now].size(); i++){
to = g[now][i];
if (!vis[to]){
dfs(to);
}
if (c[now] == 'X'){
if (dp[to].b>dp[now].b){
dp[now] = dp[to];
}
}
else if (c[now] == 'A'){
if (dp[to].a > dp[now].a){
dp[now] = dp[to];
}
}
}
vis[now] = true;
}
void start(){
MM(vis, false);
for (int i = 1; i <= n; i++){
if (m[i] == 0){
choice[i].push_back(grade[i]);
vis[i] = true;
}
}
find(1);
MM(vis, false);
for (int i = 1; i <= n; i++){
if (m[i] == 0){
vis[i] = true;
dp[i] = grade[i];
}
else{
dp[i].a = 0;
dp[i].b = 0;
}
}
dfs(1);
}
int main(){
int T;
cin >> T;
while (T--){
cin >> n;
for (int i = 1; i <= n; i++){
g[i].clear();
choice[i].clear();
}
for (int i = 1; i <= n; i++){
cin >> m[i];
if (m[i] == 0){
cin >> grade[i].a >> grade[i].b;
}
else{
int temp;
for (int x = 1; x <= m[i]; x++){
cin >> temp;
g[i].push_back(temp);
}
cin >> c[i];
}
}
start();
int ans=0;
for (int i = 0; i < (int)choice[1].size(); i++){
if (choice[1][i].b>ans){
ans = choice[1][i].b;
}
}
cout<<dp[1].b<<" "<< ans << endl;
}
return 0;
}
hdu 5005
最新推荐文章于 2020-05-02 22:30:00 发布