-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (63 loc) · 1.74 KB
/
Copy pathmain.cpp
File metadata and controls
75 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
bool val_included(vector<int> vec,int value){
for(int x:vec){
if (x == value){
return true;
}
}
return false;
}
bool is_both_exist_in_array(vector<int> vec,int value1,int value2){
if(val_included(vec,value1) && val_included(vec,value2)){
return true;
} else {
return false;
}
}
int main() {
vector<array<int, 3>> edges = {
{1, 2, 8},
{4, 5, 2},
{7, 8, 1},
{3, 4, 6},
{8, 3, 5},
{7, 6, 3}
};
vector<array<int,3>> p_vec;
vector<array<int,3>> c_vec;
for(int i=0;i<(int)edges.size()-1;i++){
for(int j=0;j<(int)edges.size()-1-i;j++){
if(edges[j][2] > edges[j+1][2]){
array<int,3> temp = edges[j];
edges[j] = edges[j+1];
edges[j+1] = temp;
}
}
}
//cycle이면 해당 array 버림 (p)
vector<int> existed_nodes;
for(int i=0;i<(int)edges.size();i++){
if(is_both_exist_in_array(existed_nodes,edges[i][0],edges[i][1])){
cout << "p {" << edges[i][0] << edges[i][1] << edges[i][2] << "}" << endl;
} else {
cout << "c {" << edges[i][0] << edges[i][1] << edges[i][2] << "}" << endl;
}
if(!val_included(existed_nodes,edges[i][0])){
existed_nodes.push_back(edges[i][0]);
}
if(!val_included(existed_nodes,edges[i][1])){
existed_nodes.push_back(edges[i][1]);
}
}
//아니면 해당 array안버림
// 범위 기반 for문을 활용한 출력
return 0;
}