QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355269 | #7883. Takeout Delivering | BUET_POTATOES# | WA | 84ms | 26660kb | C++20 | 1.9kb | 2024-03-16 15:04:37 | 2024-03-16 15:04:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int p[N];
vector<int> V[N];
void init(int n){
for(int i = 0; i < n; i++)p[i] = i, V[i] = vector<int>(1, i);
}
int f(int ind){
return p[ind] = (ind == p[ind] ? ind : f(p[ind]));
}
vector<int> un(int u, int v, int check){
u = f(u);
v = f(v);
if(u == v)return vector<int>();
if(V[u].size() < V[v].size())swap(u, v);
check = f(check);
vector<int> ret;
if(u == check)ret = V[v];
else if(v == check)ret = V[u];
p[v] = u;
while(V[v].empty()){
V[u].push_back(V[v].back());
V[v].pop_back();
}
return ret;
}
int when[2][N];
void solv(int ces){
int n, m;
cin >> n >> m;
vector<tuple<int, int, int>> ed(m);
for(auto &[d, u, v] : ed){
cin >> u >> v >> d;
u--, v--;
}
sort(ed.begin(), ed.end());
init(n);
memset(when, -1, sizeof when);
when[0][0] = 0;
for(auto [d, u, v] : ed){
auto t = un(u, v, 0);
for(auto x : t){
// cout << x << endl;
when[0][x] = d;
}
}
init(n);
when[1][n - 1] = 0;
for(auto [d, u, v] : ed){
auto t = un(u, v, n - 1);
for(auto x : t)when[1][x] = d;
}
// cout << when[0][1] << ' ' << when[1][3] << endl;
int ans = 2e9 + 2;
for(auto [d, u, v] : ed){
int a = when[0][u], b = when[1][v];
if(a != -1 && b != -1 && a <= d && b <= d)ans = min(ans, d + max(a, b));
swap(u, v);
a = when[0][u], b = when[1][v];
if(a != -1 && b != -1 && a <= d && b <= d)ans = min(ans, d + max(a, b));
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
// cin>>tc;
for(int ces=1; ces<=tc; ces++){
solv(ces);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6140kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: -100
Wrong Answer
time: 84ms
memory: 26660kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
2000000002
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '2000000002'