QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398397 | #3770. Minimum Spanning Tree | xlwang# | AC ✓ | 520ms | 12788kb | C++14 | 1.9kb | 2024-04-25 11:37:15 | 2024-04-25 11:37:16 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=2e5+10;
struct edge{
int x,y,a,b,z;
}ed[Maxn];
inline bool cmp(edge a,edge b){return a.z<b.z;}
int fa[Maxn];
inline int getfa(int x){
if(fa[x]==x) return x;
return fa[x]=getfa(fa[x]);
}
int n,m;
inline int getans(int p){
fr(i,1,m) ed[i].z=ed[i].a+ed[i].b*p;
sort(ed+1,ed+m+1,cmp);
fr(i,1,n) fa[i]=i;
int ans=0;
fr(i,1,m){
int x,y;
x=ed[i].x,y=ed[i].y;x=getfa(x),y=getfa(y);
if(x==y) continue;
fa[getfa(x)]=y,ans+=ed[i].z;
}
return ans;
}
inline void work(){
int l,r;l=read(),r=read();
fr(i,1,m) ed[i].x=read(),ed[i].y=read(),ed[i].a=read(),ed[i].b=read();
int ans=0;
if(getans(l)<getans(r)) ans=l;
else ans=r;
writeln(getans(ans));
}
inline void init(){
while(cin>>n>>m) work();
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 520ms
memory: 12788kb
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