#include #include #include #include using namespace std; const long long INF = 1000000000000000000LL; const int MAXN = 1000000 + 5; int n, m, k; long long dst[MAXN]; int ii, f[MAXN], t[MAXN], p[MAXN], v[MAXN], x, y, z, id, tag[MAXN]; bool spc[MAXN]; set > S; inline void add_edge (int x, int y, int z) { t[++ii] = y; p[ii] = f[x]; f[x] = ii; v[ii] = z; } inline void update (int vn, long long vv, int tg) { if (dst[vn] <= vv) return ; if (S.find(make_pair(vv, vn)) != S.end()) S.erase(S.find(make_pair(vv, vn))); dst[vn] = vv; tag[vn] = tg; S.insert(make_pair(vv, vn)); } int main(int argc, const char * argv[]) { cin >> n >> m; int aa = 0; for(int i = 1; i <= n; i++) { cin >> id; spc[i] = id; aa += id; } if (aa < 2) { cout << "No luck at all" << endl; return 0; } for(int i = 1; i <= m; i++) { cin >> x >> y >> z; // assert(1 <= x && x <= n); // assert(1 <= y && y <= n); // assert(x != y); // assert(1 <= z && z <= 10000); add_edge(x, y, z); add_edge(y, x, z); // S.insert(make_pair(x, y)); // S.insert(make_pair(y, x)); } // assert(S.size() == 2 * m); S.clear(); for(int i = 1; i <= n; i++) dst[i] = INF; for(int i = 1; i <= n; i++) if (spc[i]) { tag[i] = -1; update(i, 0, i); } else tag[i] = -1; while (S.size()) { int vn = S.begin()->second; S.erase(S.begin()); int qq = f[vn]; while (qq > 0) { update(t[qq], dst[vn] + v[qq], tag[vn]); qq = p[qq]; } } long long ret = INF; int ra, rb; for(int i = 1; i <= n; i++) { int qq = f[i]; while (qq > 0) { int to = t[qq]; if (tag[to] != tag[i]) { ret = min(ret, dst[to] + dst[i] + v[qq]); if (ret == dst[to] + dst[i] + v[qq]) { ra = tag[to]; rb = tag[i]; } } qq = p[qq]; } } if (ret == INF) cout << "No luck at all" << endl; else cout << ret << endl << ra << " " << rb << endl; return 0; }