답안 #886773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886773 2023-12-12T22:47:28 Z WonderfulWhale 시간이 돈 (balkan11_timeismoney) C++17
5 / 100
2000 ms 9128 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

int n, m;
vector<pair<int, int>> G[209];
vector<pair<pii, int>> edges;
vector<int> cur;
vector<pii> G2[209];
bool used[10009];

bool vis[209];

int p[209];
int Find(int x) {
	return p[x]==x?x:p[x]=Find(p[x]);
}
void Union(int a, int b) {
	p[Find(a)] = Find(b);
}

void dfs(int x, int y) {
	vis[x] = true;
	cerr << "setting: " << x << "\n";
	for(pii z:G2[x])
		if(z.st!=y) 
			dfs(z.st, x);
}

bool improve() {
	for(int i=0;i<n;i++) G2[i].clear();
	for(int i=0;i<n-1;i++) {
		auto e = edges[cur[i]];
		G2[e.st.st].pb({e.st.nd, e.nd});
		G2[e.st.nd].pb({e.st.st, e.nd});
	}
	for(int i=0;i<n-1;i++) {
		auto e = edges[cur[i]];
		memset(vis, 0, sizeof(vis));
		dfs(e.st.st, e.st.nd);
		for(int j=0;j<m;j++) {
			if(!used[j]) {
				auto ne = edges[j];
				if(vis[ne.st.st]^vis[ne.st.nd]) {
					if(ne.nd<e.nd) {
						cur[i] = j;
						used[j] = true;
						used[cur[i]] = false;
						return true;
					}
				}
			}
		}
	}
	return false;
}
	
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;
	iota(p, p+n, 0);
	for(int i=0;i<m;i++) {
		int a, b, c, _;
		cin >> a >> b >> c >> _;
		G[a].pb({b, c});
		G[b].pb({a, c});
		edges.pb({{a, b}, c});
	}
	random_shuffle(all(edges));
	for(int i=0;i<m;i++) {
		auto [x, y] = edges[i];
		if(Find(x.st)!=Find(x.nd)) {
			used[i] = true;
			cur.pb(i);
			Union(x.st, x.nd);
		} 
	}
	while(improve()) {}
	int Sum=0;
	vector<pii> ans;
	for(int x:cur) {
		Sum += edges[x].nd;
		ans.pb(edges[x].st);
	}
	cout << Sum << " " << Sum << "\n";
	for(pii x:ans) 
		cout << x.st << " " << x.nd << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 980 KB Output is correct
2 Incorrect 1 ms 600 KB Output isn't correct
3 Incorrect 3 ms 348 KB Output isn't correct
4 Incorrect 57 ms 564 KB Output isn't correct
5 Incorrect 1865 ms 7300 KB Output isn't correct
6 Execution timed out 2045 ms 8408 KB Time limit exceeded
7 Execution timed out 2065 ms 8348 KB Time limit exceeded
8 Execution timed out 2055 ms 8692 KB Time limit exceeded
9 Incorrect 1 ms 348 KB Output isn't correct
10 Incorrect 4 ms 348 KB Output isn't correct
11 Incorrect 2 ms 348 KB Output isn't correct
12 Incorrect 74 ms 596 KB Output isn't correct
13 Incorrect 65 ms 516 KB Output isn't correct
14 Execution timed out 2057 ms 7764 KB Time limit exceeded
15 Execution timed out 2025 ms 8096 KB Time limit exceeded
16 Execution timed out 2051 ms 8428 KB Time limit exceeded
17 Execution timed out 2041 ms 8560 KB Time limit exceeded
18 Execution timed out 2041 ms 8024 KB Time limit exceeded
19 Execution timed out 2031 ms 8760 KB Time limit exceeded
20 Execution timed out 2061 ms 9128 KB Time limit exceeded