QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424672 | #5034. >.< | Nityacke | 0 | 72ms | 181380kb | C++14 | 1.9kb | 2024-05-29 15:19:55 | 2024-05-29 15:19:56 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N=4e5+5;
int n,m,k,tot,fw[N],ed[N],fail[N],rt[N],dis[N];
vector<pair<int,int>>G[N];
unordered_map<int,int>ch[N];
struct tree{int lc,rc,to,w;}t[N*20];
#define k1 t[k].lc
#define k2 t[k].rc
#define mid ((l+r)>>1)
inline void ins(int &k,int q,int x,int to,int w,int l=1,int r=n){
t[k=++tot]=t[q];
if(l==r) return t[k].to=to,t[k].w=w?w:t[k].w,void();
if(x<=mid) ins(k1,t[q].lc,x,to,w,l,mid);
else ins(k2,t[q].rc,x,to,w,mid+1,r);
}
inline int ask(int k,int x,int l=1,int r=n){
if(!k||l==r) return t[k].to;
if(x<=mid) return ask(k1,x,l,mid);
else return ask(k2,x,mid+1,r);
}
priority_queue<pair<int,int>>Q;
inline void update(int &k,int w,int l=1,int r=n){
if(!k) return;
if(l==r){
int to=t[k].to;
if(!ed[to]&&w+t[k].w<dis[to]) Q.push({-(dis[to]=w+t[k].w),to});
return;
}
update(k1,w,l,mid),update(k2,w,mid+1,r),k=0;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for(int i=1,u,v,w;i<=m;++i)
cin>>u>>v>>w,G[u].pb({v,w});
for(int i=1;i<=n;++i) fw[ch[0][i]=++tot]=i;
int cnt,p,u;
while(k--){
cin>>cnt,p=0;
while(cnt--){
cin>>u;
if(!ch[p][u]) ch[p][u]=++tot;
fw[p=ch[p][u]]=u;
}
ed[p]=1;
}
queue<int>q;tot=0;
for(int i=1;i<=n;++i) q.push(ch[0][i]),ins(rt[0],rt[0],i,i,0);
for(int i=1;i<=n;++i)
for(auto j:G[i]) ins(rt[i],rt[i],j.fi,j.fi,j.se);
while(q.size()){
int x=q.front();q.pop();
ed[x]|=ed[fail[x]];
if(!rt[x]) rt[x]=rt[fail[x]];
for(auto i:ch[x])
ins(rt[x],rt[x],i.fi,i.se,0),q.push(i.se),
fail[i.se]=ask(rt[fail[x]],i.fi);
}
if(ed[1]) return cout<<"-1\n",0;
memset(dis,0x3f,sizeof dis),Q.push({dis[1]=0,1});
while(Q.size()){
int x=Q.top().se,w=-Q.top().fi;Q.pop();
if(fw[x]==n) return cout<<w<<"\n",0;
if(w==dis[x]) update(rt[x],w);
}
cout<<"-1\n";
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 41764kb
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:
1386883396
result:
wrong answer 1st lines differ - expected: '1970522617', found: '1386883396'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 72ms
memory: 181380kb
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:
643204462
result:
wrong answer 1st lines differ - expected: '2526392504', found: '643204462'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%