1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #include<bits/stdc++.h> #define int long long #define ull unsigned long long #define maxn 205 #define put() putchar('\n') #define Tp template<typename Ty> #define Ts template<typename Ty,typename... Ar> using namespace std; void read(int &x){ int f=1;x=0;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();} x*=f; } namespace Debug{ Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;} #define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; #define fi first #define se second #define mk make_pair const int mod=1e9+7; int power(int x,int y=mod-2) { int sum=1; while (y) { if (y&1) sum=sum*x%mod; x=x*x%mod;y>>=1; } return sum; } struct yyy { int x,y,a,b,w; }e[10005]; int fa[maxn],ans=1e18,ansa=1e9,ansb=1e9,n,m; int getfa(int x) {return x==fa[x]?x:fa[x]=getfa(fa[x]);} bool cmp(yyy x,yyy y) {return x.w<y.w;} pair<int,int> calc(int s,int t) { int i,x,y; for (i=1;i<=m;i++) e[i].w=s*e[i].a+t*e[i].b; sort(e+1,e+1+m,cmp); for (i=1;i<=n;i++) fa[i]=i; int tmp1=0,tmp2=0; for (i=1;i<=m;i++) { x=e[i].x,y=e[i].y; if (getfa(x)^getfa(y)) { fa[getfa(x)]=getfa(y); tmp1+=e[i].a,tmp2+=e[i].b; } } if (ans>tmp1*tmp2||(ans==tmp1*tmp2&&ansa>tmp1)) { ans=tmp1*tmp2,ansa=tmp1,ansb=tmp2; } return mk(tmp1,tmp2); } int cross(pair<int,int> s,pair<int,int> t) {return s.fi*t.se-s.se*t.fi;} void solve(pair<int,int> s,pair<int,int> t) { auto tmp=calc(s.se-t.se,t.fi-s.fi); pair<int,int> tmp1,tmp2; tmp1=mk(s.fi-tmp.fi,s.se-tmp.se); tmp2=mk(t.fi-s.fi,t.se-s.se); if (cross(tmp1,tmp2)<0) solve(s,tmp),solve(tmp,t); } signed main(void){ int i; read(n);read(m); for (i=1;i<=m;i++) { read(e[i].x),read(e[i].y),read(e[i].a),read(e[i].b); e[i].x++,e[i].y++; } auto tmp1=calc(1,0); auto tmp2=calc(0,1); solve(tmp1,tmp2); printf("%lld %lld\n",ansa,ansb); return 0; }
|