QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136168#5042. FlowPetroTarnavskyi#RE 0ms0kbC++171.6kb2023-08-07 14:58:422023-08-07 14:58:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-07 14:58:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-07 14:58:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 1 << 17;
vector<PII> g[N];

VI vals[N];

int n;
void dfs(int v, int p, int t){
	if(v == n - 1)
		return;
	for(auto e : g[v]){
		int to = e.F;
		if(p == to)
			continue;
		vals[t].PB(e.S);
		dfs(to, v,t);
	}
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> n >> m;
	LL sum = 0;
	FOR(i, 0, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].PB(MP(b, c));
		g[b].PB(MP(a, c));
		sum += c;
	}
	int sz = SZ(g[0]);
	FOR(i, 0, sz){
		vals[i].PB(g[0][i].S);
		dfs(g[0][i].F, 0, i);
	}
	
	
	assert(m - (n - 2) == SZ(g[0]));
	assert(m % (m - (n - 2)) == 0);
	int edges = m / (m - (n - 2));
	
	LL want = sum / edges;
	LL cur = 0;
	
	set<PII> cnts;
	FOR(i, 0, sz){
		sort(ALL(vals[i]));
		cur += vals[i][0];
		cnts.insert(MP(1, i));
	}
	cout << want << " " << cur << endl;
	LL ans = 0;
	while(want != cur){
		assert(SZ(cnts));
		auto best = *cnts.begin();
		cnts.erase(cnts.begin());
		
		assert(best.F != SZ(vals[0]));
		LL change = min(want - cur, (LL)vals[best.S][best.F] - vals[best.S][best.F - 1]);
		ans += change * best.F;
		
		best.F++;
		cnts.insert(best);
	}
	cout << ans << endl;
	
	
	
	
	
	
	
	
	
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

4 3
1 2 1
2 3 2
3 4 3

output:

2 1

result: