優先隊列創建小根堆方法1:node
struct node { int v, w; bool operator<(const node &dd)const{ return w>dd.w; } //權值小的優先 }; priority_queue<node> q;
優先隊列創建小根堆方法2:spa
priority_queue<int, vector<int>, greater<int> >q;
重載cmp的方法:code
struct cmp { bool operator() (constNode& a, const Node &b) { return a.key > b.key; //這時是小根堆,改成小於號後爲大根堆 } }
關於vector的 push_back(edge(a,b) ):blog
struct edge { int to,flag; edge(int _to,int _flag):to(_to),flag(_flag){} }; vector<edge> v[200005]; scanf("%d%d",&a,&b); v[a].push_back(edge(b,0));