QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84390 | #5506. Hyperloop | Zhvv123 | WA | 2469ms | 10940kb | C++14 | 2.3kb | 2023-03-06 14:27:05 | 2023-03-06 14:27:07 |
Judging History
answer
#include<bits/stdc++.h>
#define P pair<long long,int>
#define Pair make_pair
using namespace std;
const int N=100005,M=300005;
const long long INF=1e12;
int T,n,m,ans[N],tot,rcd[M];
int nx[M<<1],fr[M<<1],to[M<<1],ct[M<<1],hd[N],ecnt;
long long dis[N];
bool vis[N];
vector<int> pos[N];
inline int read(){
int x=0;
char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9')
x=(x<<3)+(x<<1)+(c^48), c=getchar();
return x;
}
inline void add(int u,int v,int w=0){
nx[++ecnt]=hd[u], hd[u]=ecnt, fr[ecnt]=u, to[ecnt]=v;
ct[ecnt]=w, pos[w].push_back(ecnt);
}
inline void dfs0(int u){
for(register int i=hd[u],v,l=0;v=to[i],i;i=nx[i])
ct[i]=0, dfs0(v);
}
inline void dfs1(int u){
if(u==n) return void(dis[u]=0);
dis[u]=0;
for(register int i=hd[u],v;v=to[i],i;i=nx[i])
dfs1(v), dis[u]=max(dis[u],dis[v]+ct[i]);
}
inline void dfs2(int u){
int t=hd[u]; hd[u]=0;
for(register int i=t,v,l=0;v=to[i],i;i=nx[i])
if(dis[u]==dis[v]+ct[i]) (!l?hd[u]:nx[l])=i, l=i, dfs2(v);
nx[hd[u]]=0;
}
inline void Set(int w){
//cout<<"Set: "<<w<<'\n';
dfs0(1);
for(auto i:pos[w]) ct[i]=1;
}
inline void Dijkstra(){
priority_queue<P,vector<P>,greater<P> > q; q.push(Pair(0,n));
memset(dis,0x3f,sizeof(dis)), dis[n]=0;
memset(vis,0,sizeof(vis));
while(!q.empty()){
P t=q.top(); q.pop();
int u=t.second;
if(vis[u]) continue;
vis[u]=true;
for(register int i=hd[u],v;v=to[i],i;i=nx[i])
if(dis[u]+ct[i]<dis[v])
dis[v]=dis[u]+ct[i], q.push(Pair(dis[v],v));
}
}
inline void Print(int u){
ans[++tot]=u;
if(u!=n) Print(to[hd[u]]);
}
int main(){
T=read();
while(T--){
n=read(), m=read();
int mx=0;
for(register int i=1,u,v,w;i<=m;++i){
u=read(), v=read(), w=read(), rcd[i]=w;
add(u,v,w), add(v,u,w), mx=max(mx,w);
}
Dijkstra(), dfs2(1), sort(rcd+1,rcd+1+m);
for(register int i=m;i>=1;--i){
Set(rcd[i]), dfs1(1), dfs2(1);
/*
for(register int i=1;i<=n;++i) cout<<dis[i]<<' ';
cout<<'\n';
for(register int u=1;u<=n;++u)
for(register int i=hd[u],v;v=to[i],i;i=nx[i])
cout<<u<<' '<<v<<'\n';
*/
}
tot=0, Print(1), printf("%d\n",tot);
for(register int i=1;i<=tot;++i) printf("%d ",ans[i]);
putchar('\n');
ecnt=0;
for(register int i=1;i<=n;++i) hd[i]=0;
for(register int i=1;i<=m;++i) pos[rcd[i]].clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 10888kb
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: -100
Wrong Answer
time: 2469ms
memory: 10940kb
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:
wrong answer Contestant's path is not optimal lexicographically (test case 3)