#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif
const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;
void GG(){cout<<"0\n"; exit(0);}
ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
ll re=1;
while (n>0){
if (n&1) re = re*a %mo;
a = a*a %mo;
n>>=1;
}
return re;
}
ll inv (ll b, ll mo = mod){
if (b==1) return b;
return (mo-mo/b) * inv(mo%b,mo) % mo;
}
const int maxn = 1e6+5;
struct Ed{
int a,b,u,v;
};
int n,m;
int par[maxn];
int find(int x) {return x == par[x]? x : par[x] = find(par[x]);}
void reset() {
for (int i = 0; i<n; ++i) par[i] = i;
}
signed main(){
IOS();
vector<Ed> es;
cin>>n>>m;
for (int i = 0; i<m; ++i) {
int u,v,a,b; cin>>u>>v>>a>>b;
es.pb({a,b,u,v});
}
int re = 1000000;
vector<Ed> gg;
int bstA, bstB;
for (int a = 0; a <= 255; ++a) {
for (int b = 0; b <= 255; ++b) {
sort(ALL(es),[&](Ed e1, Ed e2){return e1.a * a + e1.b * b < e2.a * a + e2.b * b;});
reset();
int done = 0;
int A = 0, B = 0;
vector<int> tmp ;
for (int i = 0; i<SZ(es) && done != n-1; ++i) {
if (find(es[i].v) != find(es[i].u)) {
++done; par[find(es[i].v)] = find(es[i].u);
A += es[i].a, B += es[i].b;
tmp.pb(i);
}
}
if (A*B < re) {
re = A*B;
bstA = A, bstB = B;
gg.clear();
for (int x : tmp) gg.pb(es[x]);
}
}
}
cout<<bstA<< ' ' << bstB<<endl;
for (Ed & e : gg) {
cout<<e.u<<' '<<e.v<<endl;
}
}
Compilation message
timeismoney.cpp: In function 'int main()':
timeismoney.cpp:22:14: warning: 'bstB' may be used uninitialized in this function [-Wmaybe-uninitialized]
22 | #define endl '\n'
| ^~~~
timeismoney.cpp:70:15: note: 'bstB' was declared here
70 | int bstA, bstB;
| ^~~~
timeismoney.cpp:93:18: warning: 'bstA' may be used uninitialized in this function [-Wmaybe-uninitialized]
93 | cout<<bstA<< ' ' << bstB<<endl;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
537 ms |
384 KB |
Output isn't correct |
2 |
Correct |
36 ms |
384 KB |
Output is correct |
3 |
Incorrect |
64 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
195 ms |
504 KB |
Output isn't correct |
5 |
Incorrect |
1079 ms |
504 KB |
Output isn't correct |
6 |
Incorrect |
889 ms |
384 KB |
Output isn't correct |
7 |
Execution timed out |
2051 ms |
384 KB |
Time limit exceeded |
8 |
Execution timed out |
2037 ms |
768 KB |
Time limit exceeded |
9 |
Correct |
39 ms |
384 KB |
Output is correct |
10 |
Correct |
66 ms |
504 KB |
Output is correct |
11 |
Incorrect |
66 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
212 ms |
504 KB |
Output isn't correct |
13 |
Incorrect |
215 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
1209 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
1185 ms |
504 KB |
Output isn't correct |
16 |
Execution timed out |
2045 ms |
384 KB |
Time limit exceeded |
17 |
Execution timed out |
2053 ms |
384 KB |
Time limit exceeded |
18 |
Execution timed out |
2041 ms |
384 KB |
Time limit exceeded |
19 |
Execution timed out |
2013 ms |
896 KB |
Time limit exceeded |
20 |
Execution timed out |
2061 ms |
768 KB |
Time limit exceeded |