#include<bits/stdc++.h>
#define int long long
using namespace std;
int t[20000][4];
int MAX=1000;
int ojc[3000];
int find_u(int x)
{
if(ojc[x]==x)
return x;
return ojc[x]=find_u(ojc[x]);
}
void union_f(int x,int y)
{
x=find_u(x);
y=find_u(y);
ojc[x]=y;
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,m,x,y,s,c;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>x>>y>>s>>c;
t[i][0]=x;
t[i][1]=y;
t[i][2]=s;
t[i][3]=c;
}
vector<pair<int,int> > Q;
vector<pair<int,int> > wypisz;
int S=1e9;
int T=1e9;
for(int i=0;i<=MAX;i++)
{
for(int j=0;j<n;j++)
ojc[j]=j;
vector<pair<int,int> > mam;
Q.clear();
for(int j=1;j<=m;j++)
Q.push_back({i*t[j][2]+(MAX-i)*t[j][3],j});
sort(Q.begin(),Q.end());
int wynik=0;
s=0,c=0;
for(int i=0;i<Q.size();i++)
{
int kto=Q[i].second;
if(find_u(t[kto][0])==find_u(t[kto][1]))
continue;
s+=t[kto][3];
c+=t[kto][2];
union_f(t[kto][0],t[kto][1]);
mam.push_back({t[kto][0],t[kto][1]});
}
if(s*c<S*T)
{
S=s;
T=c;
wypisz=mam;
}
}
cout<<T<<" "<<S<<"\n";
for(int i=0;i<wypisz.size();i++)
cout<<wypisz[i].first<<" "<<wypisz[i].second<<"\n";
return 0;
}
Compilation message
timeismoney.cpp: In function 'int32_t main()':
timeismoney.cpp:49:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0;i<Q.size();i++)
| ~^~~~~~~~~
timeismoney.cpp:47:13: warning: unused variable 'wynik' [-Wunused-variable]
47 | int wynik=0;
| ^~~~~
timeismoney.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<wypisz.size();i++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
212 KB |
Output is correct |
5 |
Correct |
22 ms |
368 KB |
Output is correct |
6 |
Correct |
16 ms |
332 KB |
Output is correct |
7 |
Correct |
161 ms |
596 KB |
Output is correct |
8 |
Correct |
1040 ms |
1104 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
324 KB |
Output is correct |
12 |
Correct |
5 ms |
212 KB |
Output is correct |
13 |
Correct |
5 ms |
212 KB |
Output is correct |
14 |
Correct |
30 ms |
340 KB |
Output is correct |
15 |
Correct |
23 ms |
340 KB |
Output is correct |
16 |
Correct |
164 ms |
468 KB |
Output is correct |
17 |
Correct |
169 ms |
468 KB |
Output is correct |
18 |
Correct |
155 ms |
468 KB |
Output is correct |
19 |
Correct |
893 ms |
1108 KB |
Output is correct |
20 |
Correct |
921 ms |
1108 KB |
Output is correct |