String Reconstruction

Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.

Ivan knows some information about the string s. Namely, he remembers, that string tioccurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.

You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers.

The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings tidoesn't exceed 106, 1 ≤ xi, j ≤ 106, 1 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide.

It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.

Output

Print lexicographically minimal string that fits all the information Ivan remembers.

Examples

Input
3
a 4 1 3 5 7
ab 2 1 5
ca 1 4
Output
abacaba
Input
1
a 1 3
Output
aaa
Input
3
ab 1 1
aba 1 3
ab 2 3 5
Output
ababab

寻找一个字符串。给你一些线索(某些子串的位置),输出一个满足条件的最小字典序字符串。
暴力求解超时。可以采用并查集,若当前位置已经有子串放置,那就从已知子串的末尾继续放。并查集记录下末尾的下一位。很好的避免了重叠部分的重复枚举。有点像cys学长教过的那道next跳的题。
并查集套路题。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<algorithm>
#include<vector>
#include<iterator>
#define MAX 2000005
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std; typedef long long ll; int f[MAX];
char a[MAX];
int find(int x){
return f[x]==x?x:f[x]=find(f[x]);
}
int main()
{
int n,m,x,len,i,j,k,ii;
char s[MAX];
scanf("%d",&n);
for(i=;i<=;i++){
a[i]='a';
f[i]=i;
}
int maxx=;
while(n--){
scanf(" %s %d",s,&k);
len=strlen(s);
for(j=;j<=k;j++){
scanf("%d",&x);
int xx=find(x);
int ff=find(len+x);
for(i=xx,ii=xx-x;i<=len+x-;i++,ii++){
a[i]=s[ii];
f[find(i)]=ff;
}
if(len+x->maxx) maxx=len+x-;
}
}
for(i=;i<=maxx;i++){
printf("%c",a[i]);
}
printf("\n");
return ;
}
 

最新文章

  1. Eclipse Maven Spring MyBatis 配置
  2. gradle多模块开发
  3. 【C#】Json数据 排版算法
  4. linux查看内存
  5. SurfaceView 和 TextureView
  6. 大数据平台搭建(hadoop+spark)
  7. pinyin4j
  8. swift3.0 中NSNotification 的使用
  9. iOS开发UI篇——简单的浏览器查看程序
  10. Android minHeight/Width,maxHeight/Width
  11. 浅析Java中的反射机制原理
  12. 12. leetcode 455.Assign Cookies
  13. Java经典编程题50道之四十三
  14. 17-TypeScript代理模式
  15. 优雅的使用Linux
  16. C语言的“编译、链接”
  17. bash 刷题leetcode
  18. eclipse:显示堆内存
  19. windows上dubbo-admin的安装
  20. Linux如何从零开始搭建rsync服务器(centOS6)

热门文章

  1. JavaScript toFixed() 方法注意点
  2. Java for LeetCode 084 Largest Rectangle in Histogram【HARD】
  3. java和js互调 拨打电话
  4. render 的执行流程
  5. webpack热替换原理
  6. HDU2457 DNA repair —— AC自动机 + DP
  7. ubuntn14.04 使用 nvm创建多版本node环境
  8. z+f profiler 9012
  9. SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式
  10. CI框架上传csv文件