QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77079#5506. Hyperloopthomas_liWA 697ms11172kbC++143.8kb2023-02-13 01:48:152023-02-13 01:48:16

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 01:48:16]
  • 评测
  • 测评结果:WA
  • 用时:697ms
  • 内存:11172kb
  • [2023-02-13 01:48:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int MM = 1e5+5,inf = 0x3f3f3f3f;
int n,m; int d1[MM],dn[MM],ti; vector<pair<int,int>> adj[MM],g[MM],rg[MM];
bitset<MM> good,vis; vector<int> ans,cur;
bool rec(int u){
    if(u == n){
        cur.push_back(n);
        ans = cur;
        return true;
    }
    if(vis[u]) return false;
    cur.push_back(u);
    vis[u] = 1;
    for(auto[v,t] : g[u]){
        if(good[t] && rec(v)) return true;
    }
    cur.pop_back();
    return false;
}
void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        d1[i] = dn[i] = inf;
        g[i].clear(); rg[i].clear();
        adj[i].clear();
    }
    ti = 0;
    vis.reset(); good.reset();
    ans.clear(); cur.clear();
    vector<array<int,3>> el(m);
    for(int i = 0; i < m; i++){
        int u,v,w; cin >> u >> v >> w;
        el[i] = {u,v,w};
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    auto go = [&](int st, int dist[]){
        dist[st] = 0; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> q;
        q.push({0,st});
        while(q.size()){
            auto[d,u] = q.top(); q.pop();
            for(auto[v,w] : adj[u]) if(dist[v] > dist[u]+w){
                dist[v] = dist[u]+w;
                q.push({dist[v],v});
            }
        }
    };
    go(1,d1); go(n,dn);
    int tot = d1[n]; 
    unordered_map<int,vector<array<int,3>>> mp;
    vector<array<int,3>> rel;
    for(auto[u,v,w]:el){
        if(dn[v]+d1[u]+w == tot){
            mp[w].push_back({u,v,++ti});
            g[u].push_back({v,ti}); rg[v].push_back({u,ti}); 
            rel.push_back({u,v,ti});
            //cout << u << " " << v << " " << w << "\n";
        }
        swap(u,v);
        if(dn[v]+d1[u]+w == tot){
            mp[w].push_back({u,v,++ti});
            g[u].push_back({v,ti}); rg[v].push_back({u,ti}); 
            rel.push_back({u,v,ti});
            //cout << u << " " << v << " " << w << "\n";
        }
    }
    for(int i = 1; i <= ti; i++) good[i] = 1;
    for(int i = tot; i >= 1; i--){
        if(!mp.count(i)) continue;
        auto& vec = mp[i]; bitset<MM> cur,cur_good;
        // push low
        queue<int> q; bool fl = 0;
        for(auto[u,v,t] : vec){
            if(!good[t]) continue;
            q.push(v); cur[v] = 1; fl = 1;
            cur_good[t] = 1;
        }
        if(!fl) continue;
        while(q.size()){
            int u = q.front(); q.pop();
            for(auto[v,t] : g[u]) if(!cur[v] && good[t]){
                cur[v] = 1;
                q.push(v); 
            }
        }
        for(auto[u,v,t] : rel){
            if(!good[t]) continue;
            if(cur[v] && cur[u]) cur_good[t] = 1;
        }
        cur.reset();
        for(auto[u,v,t] : vec){
            if(!good[t]) continue;
            q.push(u); cur[u] = 1;
        }
        while(q.size()){
            int u = q.front(); q.pop();
            for(auto[v,t] : rg[u]) if(!cur[v] && good[t]){
                cur[v] = 1;
                q.push(v);
            }
        }
        for(auto[u,v,t] : rel){
            if(!good[t]) continue;
            if(cur[v] && cur[u]) cur_good[t] = 1;
        }
        /*
        cout << "for " << i << "\n";
        for(int i = 1; i <= ti; i++) cout << cur_good[i];
        cout << "\n";*/
        good &= cur_good;
    }  
    // generate
    /*
    for(int i = 1; i <= ti; i++) cout << good[i];
    cout << "\n";*/
    bool res = rec(1); assert(res);
    cout << ans.size() << "\n";
    for(int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " \n"[i==(int)ans.size()-1];
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int t; cin >> t; while(t--) solve();
}
// min length will be <= 5e4, so only sqrt distinct weights that are useful

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10500kb

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: -100
Wrong Answer
time: 697ms
memory: 11172kb

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:

wrong answer Contestant's path is not optimal lexicographically (test case 2)