Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: E. The Classic Problem
- // Contest: Codeforces - Codeforces Round #265 (Div. 1)
- // Memory Limit: 768 MB
- // Time Limit: 5000 ms
- // Date / Time: 2021-08-02 14:37:14
- // Author: cosenza
- // всё что ни делается - всё к лучшему
- // check list -> long long, special cases, array size, mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b )
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <bits/stdc++.h>
- using namespace std;
- const int mod = 1e9 + 7;
- const long long lmax = 0x3f3f3f3f3f3f3f3f;
- int binexp(long long a, long long n) {
- long long res = 1;
- while(n) {
- if(n & 1) {
- (res *= a) % mod;
- }
- (a *= a) % mod;
- n >>= 1;
- }
- return res % mod;
- }
- priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, std::greater<pair<long long, long long>>> q;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, m;
- cin >> n >> m;
- vector<pair<long long, long long>> adj[n + 7];
- vector<pair<long long, long long>> path(n + 7, {-1, -1});
- vector<long long> cost(n + 7, lmax);
- while(m--) {
- long long u, v, x;
- cin >> u >> v >> x;
- adj[u].push_back({v, x});
- adj[v].push_back({u, x});
- }
- long long x, y;
- cin >> x >> y;
- q.push({0, x});
- while(!q.empty()) {
- auto p = q.top();
- q.pop();
- long long c = p.first, a = p.second;
- if(cost[a] < c) {
- continue;
- }
- for(auto k : adj[a]) {
- long long b = k.first, d = k.second;
- if(cost[b] > (d + c) % mod) {
- path[b] = {a, d};
- cost[b] = (d + c) % mod;
- q.push({cost[b], b});
- }
- }
- }
- if(path[y].first == -1) {
- cout << -1 << "\n";
- return 0;
- }
- vector<long long> pp;
- long long v = y;
- long long totcost = 0;
- while(v != x) {
- pp.push_back(v);
- v = path[v].first;
- }
- pp.push_back(x);
- reverse(pp.begin(), pp.end());
- long long totc = 0;
- for(int i = 1; i < pp.size(); i++) {
- totc = (totc + binexp(2, path[pp[i]].second)) % mod;
- }
- cout << totc << "\n";
- cout << pp.size() << "\n";
- for(auto k : pp) {
- cout << k << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement