QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#466422 | #5034. >.< | Doqe | 40 | 12ms | 188172kb | C++14 | 3.0kb | 2024-07-07 20:04:30 | 2024-07-07 20:04:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=6e5+10,M=N*30;
int ls[M],rs[M],nx[M],tt;
inline int NEW(int p)
{
++tt;ls[tt]=ls[p],rs[tt]=rs[p],nx[tt]=nx[p];
return tt;
}
int mdf(int t,int l,int r,int k,int v)
{
int p=NEW(t);
if(l==r)return nx[p]=v,p;
int mid=l+r>>1;
if(k<=mid)ls[p]=mdf(ls[p],l,mid,k,v);
else rs[p]=mdf(rs[p],mid+1,r,k,v);
return p;
}
int ask(int p,int l,int r,int k)
{
if(l==r)return nx[p];int mid=l+r>>1;
if(k<=mid)return ask(ls[p],l,mid,k);
else return ask(rs[p],mid+1,r,k);
}
int n,m;
map<pair<int,int>,int>V;
namespace ACAM
{
// vector<int>W[N];
int rt[N],fa[N],tt,val[N],edp[N],ban[N];
int dep[N],ff[N];
map<int,int>tr[N];
void ins(vector<int>X,int x)
{
int u=0,C=0;
for(int k:X)
{
int x=u;
u=tr[u][k]?tr[u][k]:(tr[u][k]=++tt);
dep[u]=++C;edp[u]=k;ff[u]=x;
}
if(!x)ban[u]=1;else val[u]=x;
}
int getnxt(int u,int f)
{
while(u&&!tr[u].count(f))u=fa[u];
return tr[u][f];
}
void build()
{
static int q[N];
int l=1,r=0;
for(auto k:tr[0])q[++r]=k.second,rt[0]=mdf(rt[0],1,n,k.first,k.second);
while(l<=r)
{
int u=q[l++];
int z=rt[fa[u]];
for(auto k:tr[u])
{
fa[k.second]=ask(z,1,n,k.first);
assert(fa[k.second]==getnxt(fa[u],k.first));
z=mdf(z,1,n,k.first,k.second);
q[++r]=k.second;
}
for(int i=1;i<=n;++i)assert(ask(z,1,n,i)==getnxt(u,i));
rt[u]=z;
}
for(int i=1,u;u=q[i],i<=r;++i)
{
ban[u]|=ban[fa[u]];
// assert(!!val[u]+!!val[fa[u]]<=1);
val[u]+=val[fa[u]];
assert((val[u]==V[pair<int,int>{edp[ff[u]],edp[u]}]));
// cerr<<u<<": "<<val[u]<<endl;
}
}
}
int k;
long long dis[M];
int via[M],W[N];
int main()
{
cin>>n>>m>>k;
vector<pair<int,int>>Z;
for(int i=1,u,v,w;i<=m;++i)
{
cin>>u>>v>>w,ACAM::ins({u,v},w);
if(u==1)Z.emplace_back(v,w);V[pair<int,int>{u,v}]=w;
}
for(int i=1;i<=k;++i)
{
vector<int>Z;int p;cin>>p;Z.resize(p);
for(int i=0;i<p;++i)cin>>Z[i];ACAM::ins(Z,0);
}
ACAM::build();
memset(dis,0x3f,sizeof dis);
priority_queue<pair<long long,int>>Q;
int c=0;
if(!ACAM::tr[0][1])return puts("-1"),0;
int x=ACAM::tr[0][1];
dis[x]=0;Q.emplace(0,x);
long long ans=1e18;
auto jud=[&](int x,long long d){if(dis[x]>d)dis[x]=d,Q.emplace(-dis[x],x);};
while(!Q.empty())
{
auto k=Q.top();Q.pop();
int u=k.second;
// cerr<<u<<" "<<ACAM::dep[u]<<" "<<c<<" "<<ACAM::ban[u]<<endl;
if(u<=ACAM::tt&&ACAM::dep[u]<=1&&c)continue;
if(u<=ACAM::tt&&ACAM::ban[u])continue;
if(via[u])continue;via[u]=1;c=1;
// cerr<<u<<" "<<ACAM::tt<<" "<<dis[u]<<endl;
if(u<=ACAM::tt)
{
// cerr<<u<<" "<<ACAM::tt<<" "<<dis[u]<<endl;
long long l=(dis[u]+=ACAM::val[u]);
if(ACAM::edp[u]==n)ans=min(ans,l);
if(ACAM::rt[u])jud(ACAM::rt[u]+ACAM::tt,l);
}
else
{
long long l=dis[u];
u-=ACAM::tt;
if(ls[u])jud(ACAM::tt+ls[u],l);
if(rs[u])jud(ACAM::tt+rs[u],l);
if(nx[u])jud(nx[u],l);//,cerr<<"FOUND: "<<nx[u]<<" "<<ACAM::dep[nx[u]]<<endl;
}
}
if(ans>=1e18)return puts("-1"),0;
cout<<ans<<endl;
}
詳細信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 7ms
memory: 185924kb
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:
1970522617
result:
ok single line: '1970522617'
Test #2:
score: 0
Accepted
time: 4ms
memory: 186088kb
input:
35 100 0 3 12 720466531 8 12 396056603 29 21 717362482 34 13 785882968 7 13 748993858 9 28 371041056 5 22 279747660 10 13 511029466 9 10 90421686 24 13 68485905 12 17 589986641 26 3 49095373 15 24 515201376 10 33 672973479 29 31 705185599 27 22 689337965 20 4 145960570 31 28 136121037 28 5 202143094...
output:
2296067497
result:
ok single line: '2296067497'
Test #3:
score: 0
Accepted
time: 11ms
memory: 182072kb
input:
35 100 0 22 20 355360466 23 35 601550723 3 27 186544474 6 24 134507727 25 2 672165808 19 1 711018563 32 16 669385420 27 11 750652665 14 11 158441860 25 14 53347528 2 20 140122295 33 20 112964489 14 6 253781013 18 14 771123144 17 35 508607402 3 19 403442205 30 16 336645858 24 22 470183063 31 22 10734...
output:
1517028140
result:
ok single line: '1517028140'
Test #4:
score: 0
Accepted
time: 7ms
memory: 183860kb
input:
35 100 0 32 5 808438527 26 23 888346324 14 19 992303007 23 1 278329540 17 29 587913784 4 33 770924125 2 5 605204525 1 21 657667587 9 35 444108546 22 12 391857443 31 33 184589665 7 14 826884170 10 32 241928783 3 17 634515992 9 34 429624654 1 18 736971857 6 9 625772037 20 18 344038507 12 25 24408330 4...
output:
1502429426
result:
ok single line: '1502429426'
Test #5:
score: 0
Accepted
time: 12ms
memory: 185908kb
input:
35 100 0 1 9 150223804 13 25 225623874 27 10 826064515 7 31 111586392 27 4 627187519 8 7 517189480 10 13 427167940 24 14 563496 27 23 119441879 13 31 712972744 34 13 128158051 16 13 146964967 31 14 860155206 25 5 431208773 24 11 48709486 29 10 694088474 11 1 801122521 12 10 369399315 21 29 399505482...
output:
1355451140
result:
ok single line: '1355451140'
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 20
Accepted
time: 11ms
memory: 186056kb
input:
35 100 10 11 2 380526516 9 1 213280408 20 1 775174358 23 33 14349082 32 11 781584201 10 26 572662203 8 12 157664649 23 20 327195474 15 25 861545590 6 18 838910534 21 27 91640650 19 26 995166014 4 2 878565098 4 34 523383573 26 18 578962566 31 6 874478934 11 8 398592349 10 7 643306798 13 28 290421417 ...
output:
1980354133
result:
ok single line: '1980354133'
Test #7:
score: 0
Accepted
time: 8ms
memory: 186124kb
input:
35 100 10 11 1 896687117 7 26 476711390 5 32 630956 6 4 823883738 21 34 247010132 3 12 913937169 16 12 430385321 16 5 852671069 26 21 985342803 30 6 434242228 29 8 425264910 4 20 270204170 30 29 682115837 17 15 583261079 26 28 747023051 34 5 467933832 8 35 286976257 18 28 122472413 17 2 139111605 31...
output:
1221466953
result:
ok single line: '1221466953'
Test #8:
score: 0
Accepted
time: 7ms
memory: 187948kb
input:
35 100 10 22 1 14962104 21 6 543325859 8 34 566018166 33 20 98618235 25 17 262818303 12 20 406329400 8 18 609453514 24 2 538644514 9 19 692253675 2 35 402502466 6 22 643342764 32 22 125016732 24 15 592478175 9 4 983207384 27 1 8572978 33 11 455386297 8 6 80900833 21 18 876759575 6 3 498241363 3 27 7...
output:
2366165329
result:
ok single line: '2366165329'
Test #9:
score: 0
Accepted
time: 4ms
memory: 188172kb
input:
35 100 10 9 11 824356486 26 28 495355000 18 7 722666675 13 28 916320626 23 5 902191290 24 15 565350882 7 25 395415147 1 15 174378000 32 27 314954867 32 4 620502039 14 8 369888464 30 10 174528922 19 8 225961839 3 18 287338530 32 6 194825575 4 7 434071787 26 22 760578181 2 14 778364759 15 21 672777506...
output:
4621773448
result:
ok single line: '4621773448'
Test #10:
score: 0
Accepted
time: 3ms
memory: 187932kb
input:
35 100 10 8 1 955842345 8 26 487841115 13 11 431659053 32 35 736554102 34 8 223723748 2 6 474854267 10 13 343831244 9 31 652218719 33 21 18870804 21 3 657281305 33 30 354153202 13 29 96716199 13 7 930885678 28 2 403915674 12 7 428085923 9 28 518591614 27 33 676639919 7 16 293763983 29 21 317079692 8...
output:
-1
result:
ok single line: '-1'
Subtask #3:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
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:
100%
Accepted
Dependency #3:
0%