P6286 [COCI2016-2017#1] Cezar


这个题好难 真的好难

对拓扑排序不是很熟练 但是能明显感觉到强烈的先后顺序 但是就是建不了边

因为这个题要求最后的目标顺序 那我们就按照他的目标顺序进行插入字典树

这样的好处就是 已经在字典树里面同层的点一定是要在现在插入点前面出现的

前缀这个点太容易忽略了 不过题目还算良心 只有两个点有前缀 要是每个点都有前缀 那真的就暴毙了

点击查看代码
#include
using namespace std;
#define lowbit(x) x&(-x)
#define ll long long
const int maxn=1e5+5;
bool pd=true;
int tr[maxn][26];
int n,cnt,tt;
int num[maxn],inn[maxn],ans[maxn];
vectorQ[maxn];
void insert(string ss);
string s[105];
queueq;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++)cin>>num[i],insert(s[num[i]]);
	if(!pd){
		cout<<"NE"<