Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- using namespace std;
- class Graph
- {
- public:
- const int block = -1;
- int vcount, acount;
- vector<int> I, J, C, H, L;
- Graph(int _vcount, vector<int>& _i, vector<int>& _j) :vcount(_vcount), I(_i), J(_j), acount(_i.size()) {
- C.assign(acount, 0);
- H.assign(vcount, block);
- L.resize(acount);
- MakeList();
- }
- Graph(int _vcount, vector<int>& _i, vector<int>& _j, vector<int>& _c) :vcount(_vcount), I(_i), J(_j), C(_c), acount(_i.size()) {
- H.assign(vcount, block);
- L.resize(acount);
- MakeList();
- }
- void makeList() {
- for (int i(0); i < acount; ++i) {
- int _i(I[i]);
- L[i] = H[_i];
- H[_i] = i;
- }
- }
- void addArc(int i, int j) {
- L[acount] = H[i];
- H[i] = acount;
- acount++;
- }
- void showArcs() {
- cout << "Arcs:" << endl;
- for (int i(0); i < acount; ++i) {
- cout << i + 1 << ": from " << I[i] + 1 << " to " << J[i] + 1 << ", value = " << C[i] << endl;
- }
- }
- void showBeamsOfArcs() {
- cout << "Beams of arcs: " << endl;
- vector <int> ArcsList;
- for (int i(0); i < vcount; ++i) {
- ArcsList.clear();
- for (int k(H[i]); k != -1; ) {
- ArcsList.push_back(k);
- k = L[k];
- }
- int count(ArcsList.size());
- switch (count)
- {
- case 0:
- cout << "From vertex " << i + 1 << " come no arcs";
- break;
- case 1:
- cout << "From vertex " << i + 1 << " comes 1 arc: ";
- break;
- default:
- cout << "From vertex " << i + 1 << " come " << count << " arcs: ";
- }
- if (count > 0) {
- for (int k(0); k < count - 1; ++k) {
- cout << ArcsList[k] + 1 << ", ";
- }
- cout << ArcsList[count - 1] + 1;
- }
- cout << endl;
- }
- }
- };
- int main()
- {
- freopen("test.txt", "r", stdin);
- int n, m;
- cin >> n >> m;
- vector<int> _i, _j;
- int ii, jj;
- for (int i(0); i < m; ++i) {
- cin >> ii >> jj;
- _i.push_back(ii - 1);
- _j.push_back(jj - 1);
- }
- Graph G(n, _i, _j);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement