说明:大多数网上说这个题目是stl跟bfs 这里纠正一下除了一开始建一个图之外 其余跟图没有半点关系,stl也只用了一个队列,手写完全没有问题,如果你看到的博客说是stl或者bfs的话,大概率他没实现 或者没写对 或者超时。 正解是写一个结构体存时间 对其排序 插入块或者查找之前对队列中之前的时间的任务都取出执行
原代码思想:用priority_queue对 执行时间进行排序 但是超时
参考代码:改成普通队列就可以过 但是根据分析t 不是严格递增的 这样bfs中的判断是有问题的 但是竟然可以过。感觉测试数据不严谨
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+10, M = 2e5+10;
int h[N],ep, vis[N];
struct Edge{
int to,nxt;
}e[M];
int hh[N],vp;
struct node{
int val, len, nxt;
}v[30010];
int n, m, T;
struct Node{
int t, a, b;
bool operator<(const Node &b)const
{
if(t != b.t) return t > b.t;
}
};
queue<Node> q;
void add(int a,int b)
{
e[ep].to = b, e[ep].nxt = h[a]; h[a] = ep ++;
}
void addnode(int u,int ch)
{
v[++ vp].val = ch, v[vp].len = v[hh[u]].len + 1, v[vp].nxt = hh[u]; hh[u] = vp;
}
void print(int u)
{
vector<int> ans