Submission #786343

# Submission time Handle Problem Language Result Execution time Memory
786343 2023-07-18T06:46:52 Z vjudge1 timeismoney (balkan11_timeismoney) C++17
0 / 100
3 ms 404 KB
#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

int n, m;
vector<iiii> edges;

vector<iiii> edges2;

int rt[N], sz[N];

int root(int x){
	return (x == rt[x] ? x : rt[x] = root(rt[x]));
}

bool merge(int x, int y){
	x = root(x), y = root(y);
	if(x == y) return 0;
	sz[x] += sz[y];
	rt[y] = x;
	return 1;
}

bool cmp(iiii a, iiii b){
	return a.se.fi < b.se.fi;
}

pair<int, ii> answer = {oo, {0, 0}};

map<ii, ii> mpp;

void solve(ii a, ii b){
	//cout << a.fi << " " << a.se << " " << b.fi << " " << b.se << "\n";
	edges2.clear();
	int temp1 = b.fi - a.fi, temp2 = a.se - b.se, cnt = 0;
	//cout << temp1 << " " << temp2 << "\n";
	for(auto it : edges){
		edges2.pb({{it.fi.fi, it.fi.se}, {it.se.fi * temp2 + it.se.se * temp1, cnt}});
		cnt++;
	}
	sort(edges2.begin(), edges2.end(), cmp);
	int tol_a = 0, tol_b = 0;
	for(int i = 1; i <= n; i++){
		sz[i] = 1, rt[i] = i;
	}
	for(auto it : edges2){
		if(merge(it.fi.fi, it.fi.se)){
			tol_a += edges[it.se.se].se.fi;
			tol_b += edges[it.se.se].se.se;
		}
	}
	//cout << tol_a << " " << tol_b << "\n";
	if(a.fi > tol_a || a.se < tol_a){
		answer = min(answer, {a.fi * a.se, a});
		answer = min(answer, {b.fi * b.se, b});
		return;
	}
	if(mp(tol_a, tol_b) == a || mp(tol_a, tol_b) == b){
		answer = min(answer, {a.fi * a.se, a});
		answer = min(answer, {b.fi * b.se, b});
		return;
	}
	mpp[{tol_a, tol_b}] = {temp2, temp1};
	solve(a, {tol_a, tol_b});
	solve({tol_a, tol_b}, b);
}

bool cmp1(iiii a, iiii b){
	return a.se.fi < b.se.se;
}

bool cmp2(iiii a, iiii b){
	return a.se.se < b.se.se;
}

#ifdef local
void process(){
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int x, y, a, b;
		cin >> x >> y >> a >> b;
		x++, y++;
		edges.pb({{x, y}, {a, b}});
	}
	sort(edges.begin(), edges.end(), cmp1);
	for(int i = 1; i <= n; i++) sz[i] = 1, rt[i] = i;
	ii tol_1 = {0, 0};
	for(auto it : edges) if(merge(it.fi.fi, it.fi.se)) tol_1 = {tol_1.fi + it.se.fi, tol_1.se + it.se.se};
	sort(edges.begin(), edges.end(), cmp2);
	for(int i = 1; i <= n; i++) sz[i] = 1, rt[i] = i;
	ii tol_2 = {0, 0};
	for(auto it : edges) if(merge(it.fi.fi, it.fi.se)) tol_2 = {tol_2.fi + it.se.fi, tol_2.se + it.se.se};
	mpp[tol_1] = {1, 0};
	mpp[tol_2] = {0, 1};
	solve(tol_1, tol_2);
	cout << answer.se.fi << " " << answer.se.se << "\n";
	edges2.clear();
	int cnt;
	for(auto it : edges){
		edges2.pb({{it.fi.fi, it.fi.se}, {it.se.fi * mpp[answer.se].fi + it.se.se * mpp[answer.se].se, cnt}});
		cnt++;
	}
	sort(edges2.begin(), edges2.end(), cmp);
	int tol_a = 0, tol_b = 0;
	for(int i = 1; i <= n; i++){
		sz[i] = 1, rt[i] = i;
	}
	for(auto it : edges2){
		if(merge(it.fi.fi, it.fi.se)){
			cout << it.fi.fi - 1 << " " << it.fi.se - 1 << "\n";
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	freopen("kek.inp", "r", stdin);
	freopen("kek.out", "w", stdout);
	process();
}
#endif

Compilation message

timeismoney.cpp: In function 'void process()':
timeismoney.cpp:130:6: warning: unused variable 'tol_a' [-Wunused-variable]
  130 |  int tol_a = 0, tol_b = 0;
      |      ^~~~~
timeismoney.cpp:130:17: warning: unused variable 'tol_b' [-Wunused-variable]
  130 |  int tol_a = 0, tol_b = 0;
      |                 ^~~~~
timeismoney.cpp: In function 'int main()':
timeismoney.cpp:144:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  144 |  freopen("kek.inp", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
timeismoney.cpp:145:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |  freopen("kek.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
timeismoney.cpp: In function 'void process()':
timeismoney.cpp:127:6: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
  127 |   cnt++;
      |   ~~~^~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
2 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
3 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
4 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
5 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
6 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
7 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
8 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
9 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
10 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
11 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
12 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
13 Incorrect 3 ms 340 KB Unexpected end of file - int64 expected
14 Incorrect 1 ms 340 KB Unexpected end of file - int64 expected
15 Incorrect 2 ms 404 KB Unexpected end of file - int64 expected
16 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
17 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
18 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
19 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected
20 Incorrect 2 ms 340 KB Unexpected end of file - int64 expected