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 ti doesn'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

题意:给定一个字符串的部分消息,让你将其补齐,并且字典序最小。

思路:给出的消息可以得到字符串长度。现在就说需要把给出的消息都填进去,没有填到的部分用‘a’补齐,给出的消息很多重复的,直接for是不想的,我们用并查集快速的得到后面的第一个空着的位置。

(常规操作,居然想不到。。。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char c[maxn]; int ans[maxn],fa[maxn];
int find(int x){
if(x!=fa[x]) fa[x]=find(fa[x]);
return fa[x];
}
int main()
{
int N,L=;
scanf("%d",&N);
rep(i,,2e6) fa[i]=i;
rep(i,,N){
scanf("%s",c+);
int Len=strlen(c+),num; scanf("%d",&num);
rep(j,,num){
int x,pos; scanf("%d",&x); L=max(L,x+Len-);
pos=x; while(true){
pos=find(pos);
if(pos>x+Len-||!pos) break;
ans[pos]=c[pos-x+];
fa[pos]=fa[find(pos+)];
pos=fa[pos];
}
}
}
rep(i,,L){
if(ans[i]=='\0') ans[i]='a';
putchar(ans[i]);
}
return ;
}

CodeForces - 827A:String Reconstruction (基础并查集)的更多相关文章

  1. CodeForces 828C String Reconstruction(并查集思想)

    题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...

  2. Codeforces 828C String Reconstruction【并查集巧妙运用】

    LINK 题目大意 给你n个串和在原串中的出现位置,问原串 思路 直接跑肯定是GG 考虑怎么优化 因为保证有解,所以考虑过的点我们就不再考虑 用并查集维护当前每个点之后最早的没有被更新过的点 然后就做 ...

  3. String Reconstruction (并查集)

    并查集维护和我这个位置的字母连续的已经被填充的字母能到达的最右边的第一个还没有填充的位置,然后把这个位置填上应该填的东西,然后把这个位置和下一个位置连接起来,如果下一个位置还没有填,我就会把下一个位置 ...

  4. hdu 1829 基础并查集,查同性恋

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  5. Codeforces - 828C String Reconstruction —— 并查集find()函数

    题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...

  6. CodeForces - 828C String Reconstruction 并查集(next跳)

    String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...

  7. Codeforces 731C:Socks(并查集)

    http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...

  8. Codeforces 859E Desk Disorder:并查集【两个属性二选一】

    题目链接:http://codeforces.com/problemset/problem/859/E 题意: 有n个人,2n个座位. 给出这n个人初始的座位,和他们想坐的座位. 每个人要么坐在原来的 ...

  9. CodeForces - 1209D Cow and Snacks 并查集

    CodeForces - 1209D 题意 现在n种点心,每种点心只有一份,有k位客人,每位客人有两种想要吃的点心,你可以安排他们进场的顺序,每位客人会吃掉所有他想要吃的,并且还没被吃掉的点心.如果客 ...

随机推荐

  1. Python基础(13)_python模块之re模块(正则表达式)

    8.re模块:正则表达式 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节 ...

  2. [不常用] - CSRF(跨站点请求伪造)

    CSRF,Cross Site Request Forgery,即跨站点请求伪造.   这种攻击是指,在用户正常登录系统以后,攻击者诱使用户访问一些非法链接,以执行一些非法操作. 比如:如果删除用户操 ...

  3. 每天一个Linux命令(53)service命令

        service命令用于对系统服务进行管理.   (1)用法:     用法:  service  [服务]  [操作]   (2)功能:     功能:  service命令用于启动.停止.重 ...

  4. Python自然语言处理-系列一

    一:python基础,自然语言概念 from nltk.book import * 1,text1.concordance("monstrous")      用语索引 2,tex ...

  5. Android L 64位兼容32 应用程序的认识

    http://blog.csdn.net/louyong0571/article/details/44223481 关于Android L 64位系统兼容32位应用的实现的简单分析. Android ...

  6. 【Head First Servlets and JSP】笔记3:Servlet的生命周期

    1.servlet的存在就是要为客户服务.servlet的任务就是得到一个用户的请求,再发回一些响应. 请求可能很复杂,也可能很简单,例如,“为我的购物车结账”,这个请求携带了一些重要的数据,你必须知 ...

  7. iOS面试必备-iOS基础知识

    近期为准备找工作面试,在网络上搜集了这些题,以备面试之用. 插一条广告:本人求职,2016级应届毕业生,有开发经验.可独立开发,低薪求职.QQ:895193543 1.简述OC中内存管理机制. 答:内 ...

  8. Python 循环的综合应用

    # 循环综合应用1. # str = "hello,world" 把字符串给反转显示 str = "hello,world" temp = "&quo ...

  9. C语言一个细节地方的说明【防止使用不当而出错】

    1.运行如下的代码: #include <stdio.h> #include <string.h> int main() { int a; a=1; int s[4]; mem ...

  10. log files of IIS

    C:\inetpub\logs\LogFiles https://docs.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/m ...