#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME ""
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 2e2 + 9;
struct edge{
int u,v,x,y;
edge(int _u = 0,int _v = 0,int _x = 0,int _y = 0): u(_u), v(_v), x(_x), y(_y) {}
};
edge e[10004];
vector<ii> ValidEdge;
int n,m,par[MAXN],ranking[MAXN];
int sumtime = 0, sumcost = 0, numcmp;
int root(int u){
if (par[u] == u) return u;
else return par[u] = root(par[u]);
}
bool unite(int u,int v){
u = root(u);
v = root(v);
if (u != v){
if (ranking[u] <= ranking[v]) swap(u,v);
ranking[u] += ranking[v];
par[v] = u;
numcmp--;
return true;
}
return false;
}
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin>>n>>m;
iota(par+1,par+1+n,1);
fill(ranking,ranking+1+n,1);
numcmp = n;
for(int i=1;i<=m;i++){
cin>>e[i].u>>e[i].v>>e[i].x>>e[i].y;
if (unite(e[i].u,e[i].v)){
sumtime += e[i].x;
sumcost += e[i].y;
ValidEdge.pb({e[i].u,e[i].v});
}
}
if (numcmp == 1){
cout<<sumtime<<' '<<sumcost<<endl;
for(int i=0;i<ValidEdge.size();i++){
cout<<ValidEdge[i].fi<<' '<<ValidEdge[i].se<<endl;
}
}
else{
cout<<-1<<endl;
}
}
Compilation message
timeismoney.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main()
| ^~~~
timeismoney.cpp: In function 'int main()':
timeismoney.cpp:68:21: 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]
68 | for(int i=0;i<ValidEdge.size();i++){
| ~^~~~~~~~~~~~~~~~~
timeismoney.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
timeismoney.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |