QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#242182#3053. Marching CoursevlpRE 0ms0kbC++174.8kb2023-11-07 00:27:452023-11-07 00:27:46

Judging History

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

  • [2023-11-07 00:27:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-07 00:27:45]
  • 提交

answer

#include <bits/stdc++.h>
#include <list>
#define len(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define ll long long
#define ull unsigned long long
#define ld long double
#define start time_t res1 = time(NULL)
#define finish              \
  time_t res2 = time(NULL); \
  cerr << res2 - res1 << '\n'
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353;
const long long MAXLL = 9223372036854775807;
const long long MAXINT = 2147483647;

using namespace std;

void print(vector<pair<int, int>> a);

void print(vector<int> a);

void print(vector<vector<int>> a);

void print(vector<vector<char>> a);

void print(vector<char> a);

// #define mtask
 #define int ll

int n, m, p;
vector<vector<vector<ld>>> g;
vector<vector<ld>> dist;

void solve(){
    cin >> n >> m >> p;
    if(m > 4471) {
        g.resize(n);
        dist.resize(n, vector<ld>(p + 1, -1e9));
        dist[0][0] = 0;
        for (int i = 0; i < m; ++i) {
            ld u, v, d, s;
            cin >> u >> v >> d >> s;
            --u, --v;
            g[(int) u].push_back({v, d, s});
            g[(int) v].push_back({u, d, s});
        }
        for (int i = 0; i < n; ++i) {
            ld mmax = 0;
            for (auto x: g[i]) mmax = max(mmax, (ld) x[2] / (ld) x[1]);
            g[i].push_back({(ld) i, 1, mmax});
        }
        vector<pair<int, int>> bfs(n, {1e9, 0});
        bfs[0] = {0, 0};
        set<pair<int, int>> q;
        q.insert({0, 0});
        while (len(q)) {
            auto [d, cur] = *q.begin();
            q.erase(q.begin());
            for (auto x: g[cur]) {
                if (bfs[x[0]].first > bfs[cur].first + x[1]) {
                    bfs[x[0]].first = d + x[1];
                    bfs[x[0]].second = bfs[cur].second + x[2];
                    q.insert({bfs[x[0]].first, x[0]});
                } else if (bfs[x[0]].first == bfs[cur].first + x[1] && bfs[x[0]].second < bfs[cur].second + x[2]) {
                    bfs[x[0]].first = d + x[1];
                    bfs[x[0]].second = bfs[cur].second + x[2];
                    q.insert({bfs[x[0]].first, x[0]});
                }
            }
        }
        ld mmax = 0;
        //print(bfs);
        for (int cur = 0; cur < n; ++cur) {
            for (auto x: g[cur]) {
                int ind = cur;
                if (bfs[cur].first > bfs[x[0]].first) {
                    ind = x[0];
                } else if (bfs[cur].first == bfs[x[0]].first && bfs[cur].second < bfs[x[0]].second) ind = x[0];
                if (2 * bfs[ind].first > p) continue;
                ld cur = (p - 2 * bfs[ind].first) * x[2] / x[1];
                mmax = max(mmax, cur + 2 * bfs[ind].second);
            }
        }
        cout << mmax << '\n';
    }
    else{
        cin >> n >> m >> p;
        dist.resize(n, vector<ld>(p + 1, -1e9));
        vector<vector<ld>> g(2 * m);
        vector<ld> mmax(n);
        dist[0][0] = 0;
        for(int i = 0; i < m; ++i){
            ld u, v, d, s;
            cin >> u >> v >> d >> s;
            --u, --v;
            g[2 * i] = {u, v, d, s};
            g[2 * i + 1] = {v, u, d, s};
            mmax[u] = max(mmax[u], s / d);
            mmax[v] = max(mmax[v], s / d);
        }
        dist[0][0] = 0;
        for(int T = 0; T < p; ++T) {
            for(auto tmp : g) {
                int cur = tmp[0];
                int newT = T + tmp[2];
                if (newT > p) continue;
                if (dist[(int) tmp[1]][newT] < dist[cur][T] + (ld) tmp[3]) {
                    dist[(int) tmp[1]][newT] = dist[cur][T] + (ld) tmp[3];
                }
            }
            for(int i = 0; i < n; ++i){
                dist[i][T + 1] = max(dist[i][T + 1], dist[i][T] + mmax[i]);
            }
        }
        cout << dist[0][p] << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(40);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#ifdef mtask
    int t;
  cin >> t;
  while (t--)
#endif
    solve();
}

void print(vector<pair<int, int>> a) {
    for (int i = 0; i < len(a); ++i) {
        cout << a[i].first << ' ' << a[i].second << '\n';
    }
}

void print(vector<int> a) {
    for (int i = 0; i < len(a); ++i) {
        cout << a[i] << ' ';
    }
    cout << '\n';
}

void print(vector<vector<int>> a) {
    for (int i = 0; i < len(a); ++i) {
        print(a[i]);
    }
}

void print(vector<char> a) {
    for (int i = 0; i < len(a); ++i) {
        cout << a[i];
    }
    cout << '\n';
}

#ifndef int

void print(vector<ll> a) {
    for (int i = 0; i < len(a); ++i) {
        cout << a[i] << ' ';
    }
    cout << '\n';
}

#endif

void print(vector<vector<char> > a) {
    for (int i = 0; i < len(a); ++i) {
        print(a[i]);
    }
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

3 3 4
1 2 1 1
2 3 2 4
3 1 1 1

output:


result: