# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
682931 |
2023-01-17T09:52:53 Z |
vjudge1 |
Toll (APIO13_toll) |
C++17 |
|
1 ms |
340 KB |
#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[30];
long long int D[25];
long long int dfs(int c, int p, vector<vector<int>> adj) {
dis[c] = D[c];
for(int k : adj[c]) {
if(k==p) continue;
dis[c] += dfs(k, c, adj);
}
return dis[c];
}
int A[25];
int B[25];
long long int C[25];
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<int>> 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(it[2]);
adj[it[2]].push_back(it[1]);
}
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<M;i++) {
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;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |