跳到正文

个人记录

图STL

#SUSPENDED#约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年3月5日
收录
2026年1月26日
更新
2026年11月15日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

图的STL

C++
#include<bits/stdc++.h>
using namespace std;
template<typename t, typename _Alloc = std::allocator<t> >
class und_graphs : protected _Vector_base<t, _Alloc> {
	unordered_map<t,vector<pair<t,int>>>g;
	vector<t>dis;
	int maxn=0;
	void Tspfa(int pos) {
		for(auto i:g[pos]) {
			maxn=max({maxn,i.first,i.second});
			dis.resize(maxn+1);
			if(dis[i] > dis[pos] + i.first) {
				dis[i.first] = dis[pos] + i.second;
				Tspfa(i.first);
			}
		}
	}
public:
	void insert(t x,t y,int a) {
		g[x].push_back({y,a});
	}
	vector<t> get_node(t x) {
		return g[x];
	}
	size_t dot_size() {
		set<t>s;
		for(auto i:g) {
			s.insert(i.first);
			s.insert(i.second);
		}
		return s.size();
	}
	size_t edge_size() {
		int ans=0;
		for(auto i:g) {
			ans+=i.second.size();
		}
		return ans;
	}

	vector<int> spfa(){
		dis.clear();
		Tspfa();
		return dis;
	}
};
int main(){
	return 0;
}
原文