1 #include <cstdio>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5
6 using namespace std;
7 struct Road
8 {
9 int start;
10 int end;
11 int length;
12 };
13 int n,m,c1,c2;
14 int short_road_length=1,short_road_num=1,max_num=0;
15 int temp = 0,road_length_temp = 0,num_sum_temp = 0;
16 Road road_temp;
17 vector<int> city_people_num;
18 vector<Road> road;
19 vector<int> city_mark;
20 void searchnext(int start)
21 {
22 if(start == c2)
23 {
24 if(road_length_temp < short_road_length)
25 {
26 short_road_length = road_length_temp;
27 short_road_num = 1;
28 max_num = num_sum_temp;
29 }
30 else if(road_length_temp == short_road_length)
31 {
32 short_road_num += 1;
33 if(num_sum_temp>max_num)
34 max_num = num_sum_temp;
35 }
36 return;
37 }
38 for(int i = 0;i<road.size();i++)
39 {
40 if(road[i].start == start&&city_mark[road[i].end] != 1)
41 {
42 city_mark[road[i].end] = 1;
43 road_length_temp += road[i].length;
44 num_sum_temp += city_people_num[road[i].end];
45
46 searchnext(road[i].end);
47
48 city_mark[road[i].end] = 0;
49 road_length_temp -= road[i].length;
50 num_sum_temp -= city_people_num[road[i].end];
51 }
52 else if(road[i].end == start&&city_mark[road[i].start] != 1)
53 {
54 city_mark[road[i].start] = 1;
55 road_length_temp += road[i].length;
56 num_sum_temp += city_people_num[road[i].start];
57
58 searchnext(road[i].start);
59
60 city_mark[road[i].start] = 0;
61 road_length_temp -= road[i].length;
62 num_sum_temp -= city_people_num[road[i].start];
63 }
64 }
65 }
66 void search()
67 {
68 if(c1 == c2)
69 {
70 short_road_num = 1;
71 max_num = city_people_num[c1];
72 return;
73 }
74 for(int i = 0;i<road.size();i++)
75 {
76 for(int j = 0;j<city_mark.size();j++)
77 {
78 city_mark[j] = 0;
79 }
80 road_length_temp = 0;
81 num_sum_temp = 0;
82
83 if(road[i].start == c1)
84 {
85 road_length_temp += road[i].length;
86 num_sum_temp += city_people_num[road[i].start];
87 num_sum_temp += city_people_num[road[i].end];
88 city_mark[road[i].start] = 1;
89 city_mark[road[i].end] = 1;
90
91 searchnext(road[i].end);
92
93 road_length_temp -= road[i].length;
94 num_sum_temp -= city_people_num[road[i].start];
95 num_sum_temp -= city_people_num[road[i].end];
96 city_mark[road[i].start] = 0;
97 city_mark[road[i].end] = 0;
98 }
99 else if(road[i].end == c1)
100 {
101 road_length_temp += road[i].length;
102 num_sum_temp += city_people_num[road[i].start];
103 num_sum_temp += city_people_num[road[i].end];
104 city_mark[road[i].start] = 1;
105 city_mark[road[i].end] = 1;
106
107 searchnext(road[i].start);
108
109 road_length_temp -= road[i].length;
110 num_sum_temp -= city_people_num[road[i].start];
111 num_sum_temp -= city_people_num[road[i].end];
112 city_mark[road[i].start] = 0;
113 city_mark[road[i].end] = 0;
114 }
115 }
116 }
117 int main()
118 {
119 cin>>n>>m>>c1>>c2;
120
121 for(int i = 0;i<n;i++)
122 {
123 cin>>temp;
124 city_people_num.push_back(temp);
125 }
126 for(int i = 0;i<m;i++)
127 {
128 cin>>road_temp.start>>road_temp.end>>road_temp.length;
129 road.push_back(road_temp);
130 city_mark.push_back(0);
131 short_road_length +=road_temp.length;
132 }
133 search();
134 cout<<short_road_num<<" "<<max_num;
135 // int hhh;
136 // cin>>hhh;
137 }