标签:eve 更新 -- || 状态 std 区块 str lse
直接利用优先队列,将每一次会对外传播的节点当前的状态记住,同时也存储这次传播会到达的时间
每次产生和输出之前先更新就可以,但是因为一个节点可能在同一时间生成多个块,会被卡时间,只能得到80分,后续优化懒得做了
附赠一组测试数据
15 13
1 2
2 3
3 4
4 5
1 6
6 7
7 8
8 9
1 10
10 11
11 12
12 13
14 15
6 28
1 1 1
1 2 2
1 6
2 7
13 7
9 7
5 7
3 14
8 14
5 14
11 14
9 25
5 25
13 25
9 29 3
5 29 4
13 29 5
1 53
2 59 6
2 59
1 1000
3 1000
8 1000
9 1000
10 1000
13 1000
14 1000
15 1000
输出
3 0 1 2
2 0 1
1 0
1 0
1 0
3 0 1 2
1 0
1 0
3 0 1 2
2 0 1
2 0 1
2 0 1
4 0 1 2 3
5 0 1 2 3 6
5 0 1 2 3 6
5 0 1 2 3 6
5 0 1 2 3 6
5 0 1 2 3 6
5 0 1 2 3 6
5 0 1 2 3 6
1 0
1 0
代码
#include<bits/stdc++.h>
using namespace std;
struct event_bro
{
int id;
int t;
vector<int> gg;
event_bro(int id,int t):id(id),t(t){
}
bool operator<(const event_bro&a) const
{
return t>a.t;
}
};
vector<int> temp[505];
vector<int> Graph[505];
priority_queue<event_bro> pq;
void handler(int t,int gap){
while(!pq.empty()&&pq.top().t<=t){
event_bro he = pq.top();
pq.pop();
for(auto &i:Graph[he.id]){
if(temp[i].size()<he.gg.size()||
temp[i].size()==he.gg.size()&&
temp[i][temp[i].size()-1]>he.gg[he.gg.size()-1]){
temp[i]=he.gg;
event_bro __(0,0);
__.id=i;
__.t=he.t+gap;
__.gg = he.gg;
pq.push(__);
}
}
}
}
void query(int a,int b,int t){
handler(b,t);
cout<<temp[a].size()<<" ";
for(auto &i:temp[a])
cout<<i<<" ";
cout<<endl;
}
void update(int a,int b,int c,int t){
handler(b,t);
temp[a].push_back(c);
event_bro help(a,b+t);
help.gg=temp[a];
pq.push(help);
}
int main(int argc, char const *argv[])
{
freopen("1.dat","r",stdin);
freopen("ans.dat","w",stdout);
int m,n;
cin>>m>>n;
int a,b,c;
for (int i = 0; i < 502; ++i)
temp[i].push_back(0);
for (int i = 0; i < n; ++i)
{
cin>>a>>b;
Graph[a].push_back(b);
Graph[b].push_back(a);
}
int t,k;
cin>>t>>k;
while(k--){
cin>>a>>b;
// char ______=getchar();
if(getchar()==‘\n‘||cin.eof()){
query(a,b,t);
}else{
cin>>c;
update(a,b,c,t);
}
}
return 0;
}
标签:eve 更新 -- || 状态 std 区块 str lse
原文地址:https://www.cnblogs.com/Crossea/p/12797958.html