#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> root;
UnionFind(int N) {
root.resize(N);
fill(root.begin(),root.end(),-1);
}
int Find(int n) {
if(root[n]<0) return n;
int r = Find(root[n]);
root[n] = r;
return r;
}
void Merge(int x, int y) {
x = Find(x), y = Find(y);
if(x==y) return;
root[x] = y;
}
};
typedef pair<long long int, long long int> P;
long long int dis[20];
long long int D[15];
long long int dfs(int c, int p, vector<vector<P>> adj) {
dis[c] = D[c];
for(P k : adj[c]) {
if(k.first==p) continue;
dis[c] += dfs(k.first, c, adj);
}
return dis[c];
}
int A[15];
int B[15];
long long int C[15];
int S, E;
int N, M;
long long int get_ans(int c, int p) {
vector<array<long long int, 3>> V;
int i;
for(i=0;i<M;i++) V.push_back({C[i], A[i], B[i]});
V.push_back({c, S, E});
sort(V.begin(),V.end());
UnionFind UF(N);
vector<vector<P>> adj;
adj.resize(N);
for(i=0;i<V.size();i++) {
auto it = V[i];
if(it[0]==c&&UF.Find(S)==UF.Find(E)) return 0;
if(UF.Find(it[1])==UF.Find(it[2])) continue;
UF.Merge(it[1], it[2]);
adj[it[1]].push_back(P(it[2], it[0]));
adj[it[2]].push_back(P(it[1], it[0]));
}
dfs(0, -1, adj);
long long int ans = min(dis[S], dis[E]) * (c+p)/2;
return ans;
}
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int K;
cin >> N >> M >> K;
int i, j;
for(i=0;i<M;i++) {
cin >> A[i] >> B[i] >> C[i];
A[i]--;
B[i]--;
C[i] *= 2;
}
cin >> S >> E;
S--;
E--;
for(i=0;i<N;i++) cin >> D[i];
long long int ma = 0;
for(i=0;i<N;i++) {
ma = max(get_ans(C[i]+1, -1), ma);
ma = max(get_ans(C[i]-1, +1), ma);
}
cout << ma << '\n';
}
Compilation message
toll.cpp: In function 'long long int get_ans(int, int)':
toll.cpp:46:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(i=0;i<V.size();i++) {
| ~^~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:64:12: warning: unused variable 'j' [-Wunused-variable]
64 | int i, j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |