CCF-CSP 201912-4区块链

CCF-CSP 201912-4区块链

看了大佬博客(https://blog.csdn.net/richenyunqi/article/details/104155384)以后写的,本来想着看完按自己思路写,但是最后写出来差不多,但是我80分,运行超时。

#include <bits/stdc++.h>
using namespace std;

map<int, unordered_map<int, array<vector<int>, 2>>> operation;//operation[a][b][0/1]表示a时刻需要b节点需要接收的链和块
vector<vector<int>> ans(505,{0});
vector<int>graph[505];
int n,m;
int t, k;

bool Judge(vector<int> v1, vector<int> v2){
    if (v1.size() != v2.size()) return v1.size() > v2.size();
    if (v1.size() == v2.size()) return *v1.rbegin() < *v2.rbegin();
    return 0;
}

void diffuse(int u, int ti){
    for (auto v : graph[u]){
        if (Judge(ans[u], operation[ti][v][0]))
            operation[ti][v][0] = ans[u];
    }
}
void query(int a, int b){
    for (auto times: operation){
        int time = times.first;
        //cout << time << "\n";
        if (time > b) break;
        for (auto ope : times.second){
            int vertex = ope.first;
            auto link = ope.second[0];
            auto block = ope.second[1];
            bool flag1 = Judge(link, ans[vertex]);
            bool flag2 = block.size();
            if (flag1) ans[vertex] = link;
            if (flag2) {
                for (auto _ : block) ans[vertex].push_back(_);
            }
            if (flag1 || flag2){
                diffuse(vertex, time + t);
            }
        }
    }
    operation.erase(operation.begin(), operation.upper_bound(b));
    cout << ans[a].size();
    for (auto _ : ans[a]){
        cout << " " << _ ;
    }
    cout << "\n";
}

int main() {
    //freopen("out4.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    cin >> t >> k;
    while (k--){
        int a, b, c;
        cin >> a >> b;
        if (cin.get()=='\n' || cin.eof()){
            //cout << "$  " << a <<" " <<  b<<"\n";
            query(a, b);
        }else{
            cin >> c;
            operation[b][a][1].push_back(c);
            //cout << "$  " << a <<" "<< b << " " << c << "\n";
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值