QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#385272 | #3770. Minimum Spanning Tree | ucup-team1251 | AC ✓ | 641ms | 14644kb | C++20 | 1.6kb | 2024-04-10 17:07:08 | 2024-04-10 17:07:09 |
Judging History
answer
#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
#define endl "\n"
#define pb push_back
#define ll long long
#define int long long
#define pii pair<ll,ll>
#define psi pair<string, ll>
#define de cout<<1;
#define mem(a,x) memset(a,x,sizeof a)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int mod1=998244353;
const int mod2=1e9+7;
const int INF=0x3f3f3f3f;
const int N = 1e6 + 60;
int n,m,number;
int par1[N],par2[N];
int idx1,idx2;
ll findd1(ll x)
{
if(par1[x]!=x)par1[x]=findd1(par1[x]);
return par1[x];
}
ll findd2(ll x)
{
if(par2[x]!=x)par2[x]=findd2(par2[x]);
return par2[x];
}
void init()
{
rep(i,0,n)
{
par1[i]=i;
par2[i]=i;
}
}
struct node
{
int a,b;
int w;
}node1[N],node2[N];
bool cmp(node a,node b)
{
return a.w<b.w;
}
void solve()
{
int l,r;
while(cin >> n >> m >> l >> r)
{
idx1=0,idx2=0;
rep(i,1,m)
{
int a,b,x,y;
cin >> a >> b >> x >> y;
node1[idx1++]={a,b,x+l*y};
node2[idx2++]={a,b,x+r*y};
}
sort(node1,node1+idx1,cmp);
sort(node2,node2+idx2,cmp);
init();
int ans1=0,ans2=0;
rep(i,0,idx1-1)
{
int fa=findd1(node1[i].a);
int fb=findd1(node1[i].b);
if(par1[fa]!=fb)
{
par1[fa]=fb;
ans1+=node1[i].w;
}
}
rep(i,0,idx2-1)
{
int fa=findd2(node2[i].a);
int fb=findd2(node2[i].b);
if(par2[fa]!=fb)
{
par2[fa]=fb;
ans2+=node2[i].w;
}
}
cout << min(ans1,ans2)<<endl;
}
}
signed main()
{
IOS;
int _;
//cin >> _;
_ = 1;
while(_ -- )
{
number++;
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 641ms
memory: 14644kb
input:
5 6 1 5 1 2 3 1 2 3 5 -1 3 4 1 2 4 5 1 -1 5 1 5 3 2 4 3 -1 5 6 1 5 1 2 1 1 2 3 1 2 3 4 1 -10 3 4 2 10 5 1 3 10 2 4 5 -10 10 10 23 47 5 8 43 13 9 5 55 43 4 9 84 -35 5 10 78 -70 6 4 15 70 7 3 15 67 1 7 2 58 6 7 86 20 5 7 77 7 2 9 32 -91 4 15 82 98 1 2 95 12 4 3 28 100 3 1 98 -25 2 3 39 12 1 2 21 5 1 4...
output:
2 -35 748 -24308 -5125 -4533 -10093 -13414 -13237 -8499 -6782 -6151 -15031 -13554 -50866 -2745 -14186 -5363 -13339 -23410 -5161 -12841 -7280 -22485 -15045 6008 -13410 -17388 -21254 -19576 -10606 -16471 -9741 -37226 -24158 -9383 -20665 -17547 -7919 -11201 -6651 -18673 -5076 -12809 -7285 -18708 -5878 ...
result:
ok 53406 lines