QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77908 | #5506. Hyperloop | chenshi | WA | 2266ms | 17668kb | C++ | 2.1kb | 2023-02-15 21:00:13 | 2023-02-15 21:00:15 |
Judging History
answer
#include<cstdio>
#include<queue>
#include<utility>
#include<iostream>
using namespace std;
const int o=3e5+10;
int z,n,m,h[o],cnt,dis[o],dis2[o],d[o],topo[o],st[o],tp;bool vis[o],deln[o],dele[o],flg;
priority_queue<pair<int,int> > q;queue<int> Q;
struct Edge{int v,p,w;}e[o*2];
inline void ad(int U,int V,int W){e[++cnt].v=V;e[cnt].p=h[U];e[h[U]=cnt].w=W;}
inline void dijkstra(int S,int*dis){
for(int i=1;i<=n;++i) dis[i]=o,vis[i]=0;
for(q.push(make_pair(dis[S]=0,S));!q.empty();){
int t=q.top().second;
q.pop();
if(vis[t]) continue;
vis[t]=1;
for(int i=h[t];i;i=e[i].p)
if(dis[e[i].v]>dis[t]+e[i].w) q.push(make_pair(-(dis[e[i].v]=dis[t]+e[i].w),e[i].v));
}
}
void dfs(int nw){
if(vis[nw]||flg) return;
vis[nw]=1;
if((st[++tp]=nw)==n){
printf("%d\n",tp);flg=1;
for(int i=1;i<=tp;++i) printf("%d ",st[i]);
--tp;
return;
}
for(int i=h[nw];i;i=e[i].p) if(!dele[i]) dfs(e[i].v);
--tp;
}
int main(){
for(scanf("%d",&z);z--;putchar('\n'),cnt=flg=0){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i) h[i]=0;
for(int i=1,u,v,w;i<=m;++i) scanf("%d%d%d",&u,&v,&w),ad(u,v,w),ad(v,u,w);
dijkstra(1,dis);dijkstra(n,dis2);
for(int i=1;i<=n;++i) deln[i]=(dis[i]+dis2[i]!=dis[n]);
for(int i=1;i<=n;++i) for(int j=h[i];j;j=e[j].p) if(!(dele[j]=(dis[i]+e[j].w!=dis[e[j].v]))) ++d[e[j].v];
for(cnt=0,Q.push(1);!Q.empty();topo[++cnt]=Q.front(),Q.pop())
for(int i=h[Q.front()];i;i=e[i].p) if(!dele[i]) if(!--d[e[i].v]) Q.push(e[i].v);
for(int w;1;){
w=0;
for(int i=1;i<=n;++i) if(!deln[i]) for(int j=h[i];j;j=e[j].p) if(!deln[e[j].v]&&!dele[j]) w=max(w,e[j].w);
if(!w) break;
for(int i=1;i<=n;++i) dis[i]=dis2[i]=0;
for(int i=1;i<=cnt;++i) for(int j=h[topo[i]];j;j=e[j].p)
if(!dele[j]) dis[e[j].v]=max(dis[e[j].v],dis[topo[i]]+(e[j].w==w));
for(int i=cnt;i;--i) for(int j=h[topo[i]];j;j=e[j].p)
if(!dele[j]&&!deln[e[j].v]) dis2[topo[i]]=max(dis2[topo[i]],dis2[e[j].v]+(e[j].w==w));
for(int i=1;i<=n;++i) for(int j=h[i];j;j=e[j].p){
if(dis[i]+dis2[e[j].v]+(e[j].w==w)<dis[n]) dele[j]=1;
if(e[j].w==w) e[j].w=0;
}
}
for(int i=1;i<=n;++i) vis[i]=0;
dfs(1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11836kb
input:
2 4 6 1 2 1 1 3 2 2 3 1 2 4 2 3 4 1 1 4 4 6 11 1 2 9 2 3 12 3 4 3 4 5 5 5 6 10 6 1 22 2 4 9 3 6 1 4 6 5 2 5 2 3 5 8
output:
3 1 3 4 5 1 2 5 3 6
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 2266ms
memory: 11980kb
input:
600 320 1547 204 81 13768 232 97 9939 97 249 3719 201 109 14322 183 132 40881 142 143 1 275 186 24548 18 236 7907 30 317 11845 131 130 1 311 300 11704 141 92 41925 174 191 32128 119 120 1 184 183 1 310 309 1 283 270 25477 233 141 36076 212 92 13770 307 110 40656 218 137 14033 180 85 41892 200 199 44...
output:
184 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok correct (600 test cases)
Test #3:
score: -100
Wrong Answer
time: 570ms
memory: 17668kb
input:
4 100000 220000 48940 43355 42347 77914 77913 1 45236 82683 42904 22563 16038 34866 81537 81538 43088 49803 51485 25497 63071 25523 14336 44102 39850 43782 13607 92386 16724 98711 73651 46840 17775 16801 28765 5757 98829 13508 85095 48444 1 9198 43003 32678 14461 14462 1 20245 48742 18138 89120 8911...
output:
15000 1 344 92165 92164 9 12 251 254 123 318 263 210 109 202 307 28992 28991 28990 28989 28988 28987 28986 94640 94639 94638 94637 94636 94635 94634 94633 94632 94631 94630 94629 94628 94627 94626 94625 97479 97478 97477 97476 97475 97474 97473 97472 97471 97470 97469 97468 82590 82591 82592 8259...
result:
wrong answer Path uses an edge that doesn't exist (test case 1)