QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#466432 | #5034. >.< | Nesraychan | 0 | 0ms | 0kb | C++14 | 2.3kb | 2024-07-07 20:15:43 | 2024-07-07 20:15:44 |
answer
#include<bits/stdc++.h>
#define IL inline
#define reg register
#define int long long
#define N 200200
IL int read()
{
reg int x=0,f=0; reg char ch=getchar();
while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return f?-x:x;
}
int n,m,k;
std::vector<std::pair<int,int>>G[N];
int fail[N],tot;
std::map<int,int>ch[N];
bool ed[N];
IL void insert()
{
reg int len=read();
for(reg int i=1,c,p=0;i<=len;++i)
{
c=read();
if(!ch[p].count(c))ch[p][c]=++tot;
p=ch[p][c]; if(i==len)ed[p]=1;
// printf("-- [%lld, %lld]\n",i,p);
}
}
int rt[N],ls[N<<5],rs[N<<5],w[N<<5],cnt;
IL int clone(reg int o)
{
ls[++cnt]=ls[o],rs[cnt]=rs[o];
return w[cnt]=w[o],cnt;
}
void modify(reg int &o,reg int p,reg int k,reg int l=1,reg int r=n)
{
o=clone(o);
if(l==r)return w[o]=k,void();
reg int mid=l+r>>1;
if(mid>=p)modify(ls[o],p,k,l,mid);
else modify(rs[o],p,k,mid+1,r);
}
int query(reg int o,reg int p,reg int l=1,reg int r=n)
{
if(!o||l==r)return w[o];
reg int mid=l+r>>1;
return mid>=p?query(ls[o],p,l,mid):query(rs[o],p,mid+1,r);
}
IL int trans(reg int p,reg int c){return query(rt[p],c);}
IL void bfs()
{
std::queue<int>q;
for(auto &[c,x]:ch[0])q.push(x),modify(rt[0],c,x);
while(!q.empty())
{
reg int u=q.front(); q.pop();
ed[u]|=ed[fail[u]],rt[u]=rt[fail[u]];
for(auto &[c,v]:ch[u])modify(rt[u],c,v);
for(auto &[c,v]:ch[u])fail[v]=trans(fail[u],c),q.push(v);
}
}
struct Node
{
int u,p,d;
IL bool operator <(const Node &a)const{return d>a.d;}
};
std::set<std::pair<int,int>>vis;
main()
{
freopen("compete.in","r",stdin);
freopen("compete.out","w",stdout);
n=read(),m=read(),k=read();
for(reg int u,v,w;m--;)
{
u=read(),v=read(),w=read();
G[u].push_back({v,w});
}
while(k--)insert(); bfs();
std::priority_queue<Node>q;
q.push({1,trans(0,1),0});
while(!q.empty())
{
auto [u,p,dis]=q.top(); q.pop();
if(vis.count({u,p})||ed[p])continue;
vis.insert({u,p});
if(u==n)printf("%lld\n",dis),exit(0);
for(auto &[v,w]:G[u])q.push({v,trans(p,v),dis+w});
}
puts("-1");
}
詳細信息
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
35 100 0 34 7 447733879 24 20 187005344 14 34 654502303 2 31 865194349 20 33 9517055 33 15 991889891 24 33 395599993 13 16 237525328 9 5 373850826 30 34 391470240 10 7 650077565 26 10 400825980 34 27 189924713 19 27 907609573 20 10 614945312 10 5 960007605 1 7 984076202 32 25 539699728 24 31 2553027...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Dangerous Syscalls
Test #11:
score: 0
Dangerous Syscalls
input:
50000 200000 1 7542 37166 116613326 3581 43961 629220971 12873 42953 440313807 31744 5286 697832848 25882 12748 106667302 34760 29676 181570340 41570 9240 885513989 22227 35688 63657981 43180 29194 174058940 8977 41899 48262624 7465 18291 600002514 46925 9281 951474878 2115 31162 373758881 5386 3798...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%