Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef unsigned short us;
- void check_connectivity(us* indexTriples, int* connectivityOut, int all_verticies, pair<us, us> p, int index, int shift) {
- if(p.first > p.second) {
- swap(p.first, p.second);
- }
- for(int j = 0; j < all_verticies; j += 3) {
- if(j == index) continue;
- int first = indexTriples[j];
- int second = indexTriples[j + 1];
- int third = indexTriples[j + 2];
- if((p.first == first && p.second == second) || (p.first == second && p.second == first)) {
- connectivityOut[index + shift] = j;
- break;
- }
- if((p.first == second && p.second == third) || (p.first == third && p.second == second)) {
- connectivityOut[index + shift] = j + 1;
- break;
- }
- if((p.first == third && p.second == first) || (p.first == first && p.second == third)) {
- connectivityOut[index + shift] = j + 2;
- }
- }
- }
- void findConnectivity(us* indexTriples, int T, int* connectivityOut) {
- const int all_verticies = 3 * T;
- std::fill(connectivityOut, connectivityOut + all_verticies, -1);
- for(int i = 0; i < all_verticies; i += 3) {
- pair<us, us> p1 = make_pair(indexTriples[i], indexTriples[i + 1]);
- pair<us, us> p2 = make_pair(indexTriples[i + 1], indexTriples[i + 2]);
- pair<us, us> p3 = make_pair(indexTriples[i + 2], indexTriples[i]);
- check_connectivity(indexTriples, connectivityOut, all_verticies, p1, i, 0);
- check_connectivity(indexTriples, connectivityOut, all_verticies, p2, i, 1);
- check_connectivity(indexTriples, connectivityOut, all_verticies, p3, i, 2);
- }
- }
- int main()
- {
- int T = 3;
- int* connectivityOut = new int[3 * T];
- us *input = new us[9] {0,2,7,1,7,2,6,2,0};
- findConnectivity(input, 3, connectivityOut);
- for(int i = 0; i < 3 * T; ++i) {
- cout << connectivityOut[i] + 1 << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement