QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287949 | #5034. >.< | qqsv | 0 | 12ms | 37872kb | C++14 | 1.8kb | 2023-12-21 12:34:12 | 2023-12-21 12:34:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=4e5+2;
int n,m,k,u,v,w,p,cnt,ed[N],id[N],fail[N],rt[N],dp[N];
vector<pair<int,int>>g[N];
unordered_map<int,int>son[N];
struct node{int ls,rs,to,w;}t[N];
void insert(int&k,int K,int l,int r,int x,int to,int w){
k=++cnt,t[k]=t[K];
if(l==r)return t[k].to=to,t[k].w|=w,void();
int mid=l+r>>1;
if(x<=mid)insert(t[k].ls,t[K].ls,l,mid,x,to,w);
else insert(t[k].rs,t[K].rs,mid+1,r,x,to,w);
}
int query(int k,int l,int r,int x){
if(!k||l==r)return t[k].to;
int mid=l+r>>1;
if(x<=mid)return query(t[k].ls,l,mid,x);
else return query(t[k].rs,mid+1,r,x);
}
priority_queue<pair<int,int>>Q;
void update(int&k,int l,int r,int w){
if(!k)return;
if(l==r){int to=t[k].to;if(!ed[to]&&w+t[k].w<dp[to])Q.push({to,-(dp[to]=w+t[k].w)});
}else{int mid=l+r>>1;update(t[k].ls,l,mid,w),update(t[k].rs,mid+1,r,w);}
k=0;
}
signed main(){
cin>>n>>m>>k;
for(int i=1;i<=m;i++)cin>>u>>v>>w,g[u].push_back({v,w}),g[v].push_back({u,w});
for(int i=1;i<=n;i++)id[son[0][i]=++cnt]=i;
while(k--){cin>>p,u=0;while(p--){cin>>v;if(!son[u][v])son[u][v]=++cnt;id[u=son[u][v]]=v;}ed[u]=1;}
queue<int>q;cnt=0;
for(int i=1;i<=n;i++){q.push(i);for(auto j:g[i])insert(rt[i],rt[i],1,n,j.first,j.first,j.second);}
while(!q.empty()){
int u=q.front();q.pop();
ed[u]|=ed[fail[u]];//
if(!rt[u])rt[u]=rt[fail[u]];
for(auto i:son[u]){
int x=i.first,to=i.second;
insert(rt[u],rt[u],1,n,x,to,0);
if(son[fail[u]].find(x)!=son[fail[u]].end())fail[to]=son[fail[u]][x];
else fail[to]=query(rt[fail[u]],1,n,x);
q.push(to);
}
}
if(ed[1])cout<<-1,exit(0);
memset(dp,127,sizeof(dp)),Q.push({1,dp[1]=0});
while(!Q.empty()){
int u=Q.top().first,w=-Q.top().second;Q.pop();
if(id[u]==n)cout<<w,exit(0);
if(w==dp[u])update(rt[u],1,n,w);
}cout<<-1;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 37872kb
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:
2378589796
result:
wrong answer 1st lines differ - expected: '1970522617', found: '2378589796'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
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%