QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77194#5506. HyperloopzaneyuAC ✓10068ms47796kbC++204.0kb2023-02-13 10:13:012023-02-13 10:13:04

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-13 10:13:04]
  • 评测
  • 测评结果:AC
  • 用时:10068ms
  • 内存:47796kb
  • [2023-02-13 10:13:01]
  • 提交

answer

/*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
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]+1<<((i!=sz(V)-1)?" ":"\n");
    return out;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    a%=MOD;
    if(a==0) return 0;
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
vector<pii> g[maxn],v[maxn];
bool vis[maxn];
vector<int> top;
ll ds[maxn],dt[maxn];
int n;
void dfs(int u){
    if(vis[u]) return;
    vis[u]=1;
    for(auto x:v[u]){
        if(dt[x.f]+ds[u]+x.s==ds[n-1]){
            g[u].pb(x);
            dfs(x.f);
        }
    }
    top.pb(u);
}
int mx;
void dfs2(int u){
    if(vis[u]) return;
    vis[u]=1;
    for(auto x:v[u]){
        if(dt[x.f]+ds[u]+(x.s==mx)==ds[n-1]){
            if(x.s==mx) x.s=0;
            g[u].pb(x);
            dfs2(x.f);
        }
    }
}
void dij(int u,ll dist[]){
    priority_queue<pii,vector<pii>,greater<pii>> pq;
    REP(i,n) dist[i]=INF64;
    dist[u]=0;
    pq.push({0,u});
    while(sz(pq)){
        int z=pq.top().s;
        if(pq.top().f>dist[z]){
            pq.pop();
            continue;
        }
        pq.pop();
        for(auto x:v[z]){
            if(dist[x.f]>dist[z]+x.s){
                dist[x.f]=dist[z]+x.s;
                pq.push({dist[x.f],x.f});
            }
        }
    }
}
void solve(){
    int m;
    cin>>n>>m;
    REP(i,n) v[i].clear(),g[i].clear(),vis[i]=0;
    top.clear();
    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        --a,--b;
        v[a].pb({b,c}),v[b].pb({a,c});
    }
    dij(0,ds);
    dij(n-1,dt);
    dfs(0);
    REP(i,n) v[i]=g[i],g[i].clear();
    //REP(i,n) cout<<i<<':'<<v[i]<<'\n';
    REP(a,400){
        mx=0;
        REP(i,n){
            vis[i]=0;
            for(auto x:v[i]){
                MXTO(mx,x.s);
            }
        }
        if(mx==0) break;
        REP(i,n) ds[i]=dt[i]=-INF;
        ds[0]=dt[n-1]=0;
        for(int x:top){
            for(auto a:v[x]){
                MXTO(dt[x],dt[a.f]+(a.s==mx));
            }
        }
        reverse(ALL(top));
        for(int x:top){
            for(auto a:v[x]){
                MXTO(ds[a.f],ds[x]+(a.s==mx));
            }
        }
        reverse(ALL(top));
        dfs2(0);
        REP(i,n) v[i]=g[i],g[i].clear();
    }
    int p=0;
    vector<int> ans;
    while(p!=n-1){
        assert(sz(v[p]));
        ans.pb(p);
        p=v[p][0].f;
    }
    ans.pb(n-1);
    cout<<sz(ans)<<'\n';
    cout<<ans;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int t;
    cin>>t;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 8116kb

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 2 4
5
1 2 5 3 6

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 555ms
memory: 8608kb

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 87 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: 0
Accepted
time: 1170ms
memory: 47796kb

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:

35000
1 24721 24648 24647 24700 24305 24272 99392 25020 25051 25070 24443 24448 25109 25096 43056 43055 43054 43053 43052 43051 43050 43049 43048 43047 43046 43045 43044 43043 43042 43041 43040 43039 43038 43037 43036 43035 43034 43033 43032 43031 43030 43029 43028 43027 43026 43025 43024 43023 4302...

result:

ok correct (4 test cases)

Test #4:

score: 0
Accepted
time: 10068ms
memory: 32296kb

input:

4
100000 160000
5533 94547 28459
14992 20984 20548
70133 92512 27510
9013 9012 304
13621 40571 47787
305 306 262
6987 6988 135
16234 16992 40656
26246 49196 27701
19103 60272 44055
91532 91531 38290
70778 68341 35147
32524 32523 13
85786 50300 40970
49277 29735 13942
43446 34519 42455
77623 17031 34...

output:

316
1 2 3 4 5 6 97410 97409 26434 26435 26436 26437 98883 1370 1369 1368 92157 92158 4815 4816 4817 4818 50181 16985 89607 89608 24674 16979 16980 38428 13232 13233 13234 13664 13663 95009 7166 7165 7172 7163 24798 24799 11787 31031 53551 7309 7310 35482 7933 25067 32714 32715 44194 2068 72216 79593...

result:

ok correct (4 test cases)

Test #5:

score: 0
Accepted
time: 933ms
memory: 39184kb

input:

4
100000 160000
89517 25671 43802
21059 21058 1
35299 91834 43615
53383 53382 1
27213 39161 17202
10715 4050 30342
44100 44099 1
24162 28648 7378
19022 23084 37734
66056 97934 14651
31566 89391 23215
91038 91037 1
47695 47696 6099
99142 99143 1
83908 73654 15060
15551 22001 8896
55190 55189 1
26536 ...

output:

632
1 94652 94653 31254 31269 31264 31173 31238 31281 31164 31289 31200 31205 91851 99690 91847 2469 99496 2507 2566 2537 2514 2547 2552 71980 74130 74129 99693 84670 84671 84672 84673 84674 84675 84676 84677 84678 84679 84680 84681 84682 84683 84684 84685 84686 84687 84688 84689 84690 84691 84692 8...

result:

ok correct (4 test cases)