QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623923#9434. Italian Cuisineucup-team4153#RE 0ms0kbC++203.5kb2024-10-09 14:22:562024-10-09 14:23:00

Judging History

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

  • [2024-10-09 14:23:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-09 14:22:56]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 5e5 + 7;
const int inf = 0x3f3f3f3f;
int T, n, m, k;
int C[N], L[N];
vector<array<int, 3>> G[N];
vector<int> t[N];

bool operator<(const pair<int, int> o1, const pair<int, int> o2) {
    if (o1.first == o2.first)return o1.second > o2.second;
    return o1.first < o2.first;
}

struct node {
    int u, t, res;

    node(int x, int y, int z) {
        u = x;
        t = y;
        res = z;
    }

    bool operator<(const node &o) const {
        if (t == o.t)return t > o.t;
        return res < o.res;
    }
};

struct seg {
    struct node {
        int l, r, mx;
    };
    vector<node> Tree;

    void init(int siz) {
        Tree.resize(siz << 2);
    }

    void build(int k, int l, int r, vector<int> &x) {
        Tree[k].l = l;
        Tree[k].r = r;
        if (l == r) {
            Tree[k].mx = x[l];
            return;
        }
        int mid = (l + r) >> 1;
        build(k << 1, l, mid, x);
        build(k << 1 | 1, mid + 1, r, x);
        Tree[k].mx = max(Tree[k << 1].mx, Tree[k << 1 | 1].mx);
    }

    int query(int k, int l, int r, int v) {
        if (Tree[k].mx < v)return inf;
        if (l == r)return l;
        int ans = inf;
        int mid = (Tree[k].l + Tree[k].r) >> 1;
        if (l <= mid)ans = query(k << 1, l, r, v);
        if (ans != -1)return ans;
        if (r > mid)ans = query(k << 1 | 1, l, r, v);
        return ans;
    }
} Tree[N];

void dij() {
    vector<pair<int, int>> dis(n + 1, {inf, 0});
    dis[1] = {0, 0};
    priority_queue<node> que;
    que.push(node(1, 0, 0));
    vector<int> vis(n + 1, 0);
    while (!que.empty()) {
        node u = que.top();
        que.pop();
        if (vis[u.u])continue;
        vis[u.u] = 1;
        for (auto [v, c, l]: G[u.u]) {
            if (c == C[u.t] && u.res >= l) {
                if (make_pair(c, u.res - l) < dis[v]) {
                    dis[v] = {c, u.res - l};
                    que.push(node(v, dis[v].first, dis[v].second));
                    continue;
                }
            }
            int siz = t[c].size();
            int pos = upper_bound(t[c].begin(), t[c].end(), u.t) - t[c].begin();
            if (pos == siz)continue;

            pos = Tree[c].query(1, pos, siz - 1, l);
            pair<int, int> nxt = {t[c][pos], L[t[c][pos]] - l};
            if (nxt < dis[v]) {
                dis[v] = nxt;
                que.push(node(v, dis[v].first, dis[v].second));
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (dis[i].first != inf)cout << "1";
        else cout << "0";
    }
    cout << "\n";
}

void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= m; i++) {
        int u, v, c, l;
        cin >> u >> v >> c >> l;
        G[u].push_back({v, c, l});
        G[v].push_back({u, c, l});
    }
    for (int i = 1; i <= k; i++) {
        int c, l;
        cin >> c >> l;
        C[i] = c;
        L[i] = l;
        t[c].push_back(i);
    }
    for (int i = 1; i <= m; i++) {
        if (t[i].empty())continue;
        Tree[i].init(t[i].size());
        Tree[i].build(1, 0, t[i].size() - 1, t[i]);
    }
    dij();
    for (int i = 1; i <= n; i++)G[i].clear();
    for (int i = 1; i <= m; i++) {
        t[i].clear();
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while (T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:


result: