QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757602 | #7883. Takeout Delivering | surenjamts# | WA | 135ms | 56192kb | C++20 | 1.6kb | 2024-11-17 11:07:22 | 2024-11-17 11:07:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define S second
#define int long long
int n,m;
int sz[300005];
int par[300005];
vector<tuple<int,int,int>> edges;
vector<pair<int,int>> adj[300005];
int fin(int x){
if(par[x]==x) return x;
else return par[x]=fin(par[x]);
}
bool same(int x, int y){
x=fin(x), y=fin(y);
return x==y;
}
void unite(int x, int y){
x=fin(x), y=fin(y);
if(x==y){
return;
}
if(sz[x]<sz[y]) swap(x,y);
sz[x]+=sz[y];
par[y]=x;
}
void dfs(int node, int pre, int we){
if(node==n){
cout<<we<<endl;
return;
}
for( pair<int,int> i: adj[node]){
if(i.second!=pre){
dfs(i.second,node,we+i.first);
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
cin>>n>>m;
for(int i=0; i<m; i++){
int u,v,w;
cin>>u>>v>>w;
edges.push_back({w,u,v});
// adj[u].push_back({w,v});
//adj[v].push_back({w,u});
}
for(int i=0; i<=n; i++){
sz[i]=1;
par[i]=i;
}
priority_queue<int> q;
sort(edges.begin(),edges.end());
for(auto [w,u,v] : edges){
if(!same(u,v)){
unite(u,v);
adj[u].push_back({w,v});
adj[v].push_back({w,u});
q.push(w);
}
// cout<<":L"<<endl;
//cout<<w<<" "<<u<<" "<<v<<endl;
int x=1, y=n;
x=fin(x), y=fin(y);
if(x==y){
break;
}
}
dfs(1,0,0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5668kb
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: 135ms
memory: 56192kb
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:
149949075068663
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '149949075068663'