由于某些字符,会我转为你,你转为他,他转为我,形成一个环,所以先缩点后得到一个DAG森林。
对于森林里的每棵树,做一次取最大值的dp即可。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=6e5+5;
int n,m,tot,ans1,ans2,id[N],dp1[N],dp2[N],u[N],v[N],nn;
char str[N];
bool vis[N];
int now,top,col,dfn[N],low[N],sta[N],color[N];
struct number{int v,len;}num[N];
map<string,int>mp;
int cnt,head[N];
struct edge{int next,to;}e[N<<1];inline void add(int u,int v)
{cnt++;e[cnt].next=head[u];e[cnt].to=v;head[u]=cnt;
}void tarjan(int u)
{dfn[u]=low[u]=++now;sta[++top]=u;for (register int i=head[u]; i; i=e[i].next)if (!dfn[e[i].to]){tarjan(e[i].to);low[u]=min(low[u],low[e[i].to]);}else if (!color[e[i].to]) low[u]=min(low[u],low[e[i].to]);if (dfn[u]==low[u]){col++;while (sta[top]!=u) {int now=sta[top];if (num[now].v<dp1[col] || num[now].v==dp1[col] && num[now].len<dp2[col]) dp1[col]=num[now].v,dp2[col]=num[now].len; color[sta[top]]=col;top--; }int now=sta[top];if (num[now].v<dp1[col] || num[now].v==dp1[col] && num[now].len<dp2[col]) dp1[col]=num[now].v,dp2[col]=num[now].len; color[sta[top]]=col;top--;   }
}void dfs(int u)
{if (vis[u]) return;vis[u]=true;for (register int i=head[u]; i; i=e[i].next){dfs(e[i].to);if (dp1[e[i].to]<dp1[u] || dp1[e[i].to]==dp1[u] && dp2[e[i].to]<dp2[u]) dp1[u]=dp1[e[i].to],dp2[u]=dp2[e[i].to];}
}signed main(){int inf=1e18;for (register int i=1; i<=1e5; ++i) dp1[i]=dp2[i]=inf;scanf("%lld",&n);for (register int i=1; i<=n; ++i){scanf("%s",str);int len=strlen(str);int now=0;for (register int j=0; j<len; ++j){if (str[j]>='A' && str[j]<='Z') str[j]=str[j]-'A'+'a';if (str[j]=='r') now++;}int t=mp[str];if (!t) t=mp[str]=++tot;num[t].len=len; num[t].v=now;id[i]=t;}scanf("%lld",&m);while (m--){scanf("%s",str);int len=strlen(str);int now=0;for (register int i=0; i<len; ++i){if (str[i]>='A' && str[i]<='Z') str[i]=str[i]-'A'+'a';if (str[i]=='r') now++;}int x=mp[str];if (!x) x=mp[str]=++tot;num[x].len=len; num[x].v=now;scanf("%s",str);len=strlen(str);now=0;for (register int i=0; i<len; ++i){if (str[i]>='A' && str[i]<='Z') str[i]=str[i]-'A'+'a';if (str[i]=='r') now++;}int y=mp[str];if (!y) y=mp[str]=++tot;num[y].len=len; num[y].v=now;add(x,y);u[++nn]=x; v[nn]=y;}for (register int i=1; i<=tot; ++i) if (!dfn[i]) tarjan(i);cnt=0; memset(head,0,sizeof(head));for (register int i=1; i<=nn; ++i)if (color[u[i]]!=color[v[i]]) add(color[u[i]],color[v[i]]);for (register int i=1; i<=n; ++i){dfs(color[id[i]]);ans1+=dp1[color[id[i]]];ans2+=dp2[color[id[i]]];}printf("%lld %lld\n",ans1,ans2);
return 0;
}

CF467D Fedor and Essay相关推荐

  1. [CF467D]Fedor and Essay

    Fedor and Essay 题解 再次吐槽一下某网站的翻译 由于同义词之间连得上单向边,很容易发现,我们可以根据它得到一个有向的图,一个点能够到达的点就是能够被转化成的点. 于是,我们就很容易想到 ...

  2. CF467D Fedor and Essay 有向图强连通分量+缩点

    文章目录 一.题目 二.题解 三.Code Thanks! 一.题目 传送门 翻译: 在你帮助Fedor在«Call of Soldiers 3»这款游戏中找到朋友之后,他完全停止了学习.今天,英语老 ...

  3. Codeforces467 Fedor and Essay

    题意:输入m个字符串,以及n种关系,这n种关系的两个字符串可以由前面替换为后面,要让原文的r个数最少且最短 题解:这n对关系可以发现是一个有向图,每一个图一个点权(t的个数,长度),直接暴力对原文每一 ...

  4. PoolTogether本周Loot Box奖金组合中新增加入ESSAY代币

    以太坊无损彩票PoolTogether本周的Loot Box奖金中加入10枚ESSAY代币,价格约合332美元 .ESSAY代币是Snapchat前软件工程师在内容众筹平台Mirror上发起首次众筹项 ...

  5. 美国本科申请Essay的写作注意事项

    众所周知,许多美国大学本科申请文书除了必要的PS之外,也设有命题essay,往往是从多个题目中选择几篇进行写作,一般字数要求较PS来说要少一些,但也不能忽略其重要性.学校往往会通过不同题目的essay ...

  6. 英文Essay写作中存在哪些门道?

    刚进入英国学校学习的小伙伴,每次放假都要赶Essay.那么什么是Essay呢?Essay怎么写呢?今天我们就来讲讲Essay中的门道. A little partner who has just en ...

  7. Writing a Cause and Effect Essay

    Defining Cause and Effect The easiest way to define cause and effect is "one thing leads to ano ...

  8. 【雅思大作文考官范文】——第三篇:essay 'skeleton'(散文“骨架”)

    转载地:https://ielts-simon.com/ 雅思七分作文更新:多看多写,才会有进步噢!! 题目: Some people believe that developments in the ...

  9. On the Use of BERT for Automated Essay Scoring: Joint Learning of Multi-Scale Essay Representation学习

    BERT在作文自动评分中的应用:多尺度作文表征的联合学习 1. Introduction 针对预训练语言模型在AES领域效果不好的问题进行分析: 首先,预先训练的模型通常是在句子层面上进行训练,但没有 ...

最新文章

  1. 刚刚,马斯克再次创造航天历史!SpaceX首次载人发射任务成功
  2. ad 原理图差分线_再改原理图,得加钱检查原理图PCB系列教程17
  3. 面试中的 10 大排序算法总结
  4. OPEN×××拨入后给不同的用户分配不同的访问权限
  5. 基于Flume的美团日志收集系统
  6. JavaScript 中typeof、instanceof 与 constructor 的区别?
  7. SQL编程:外键约束
  8. Speex的安装使用
  9. codeforces 558 D Guess Your Way Out! II
  10. Thinkpad E430 移除网卡白名单
  11. 清华大学--代理服务器
  12. 供应链库存管理-库存控制策略
  13. 微信ANDROID版本解析包错误,终于弄明白为什么手机安装软件会出现“解析包出现问题”...
  14. Win7电脑上如何增加磁盘分区?
  15. python按某列拆分excel表格_把一张Excel表按照固定列分成不同工作薄的小白方法...
  16. Android——自建CA证书,实现https请求
  17. python实现Excel多行多列的转换
  18. Yuma格式历书的总结
  19. 基于机器学习的技术术语识别研究综述
  20. 十大iOS体育游戏评点

热门文章

  1. Android9.0 应用待机群组
  2. java发送邮件到qq邮箱_Java利用javax.mail发送邮件至QQ邮箱
  3. LOJ #570. 「LibreOJ Round #11」Misaka Network 与任务
  4. 剑指Offer 第1天 第2天
  5. 【Linux】报错 too many open file
  6. python中的方法和函数的区别_Python中函数和方法的区别
  7. vue计算属性和方法的区别
  8. 【百度小程序】细数百度小程序踩的坑
  9. 多用户 php源码_PHP多用户网络日记(青春日记) v1.0
  10. java jpanel 位置_java-是否有更好的方法来设置JPanel图形的初始位置?)