답안 #859324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859324 2023-10-10T04:09:34 Z maks007 Graph (BOI20_graph) C++14
0 / 100
2 ms 604 KB
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
 
signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <pair <int, double>> g[n];
	vector <double> node(n, (double)1e9), ans(n);
	double mn = 1e9;
	function<void(int)> dfs=[&](int v) {
		node[v] = 0;
		for(auto [i, j] : g[v]) {
			if(!node[i]) continue;
			dfs(i);
		}
	};
	function<void(int)> rec=[&](int i) {
		// cout << i << " ";
		if(i==n) {
			for(int j = 0; j < n; j ++) {
				for(auto [k, w] : g[j]) {
					if(node[k] + node[j] == w) continue;
					return;
				}
			}
			double sum = 0.0;
			for(auto i : node) sum += fabs(i);
			// cout << mn << " ";
			if(sum < mn) {
				ans = node;
			
				mn = min(mn, sum);
			}
			return;
		}
		for(double val = -2; val < 3; val += 0.25) {
			node[i] = val;
			rec(i+1);
			node[i] = 1e9;
		}
	};
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		u --, v --;
		int w;
		cin >> w;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	int cnt = 0;
	for(int i = 0; i < n; i ++) {
		if(!node[i]) continue;
		cnt ++;
		dfs(i);
	}
	assert(cnt == 1);
	for(auto &j : node) j = 1e9;
	rec(0);
	if(mn == 1e9) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES" << "\n";
	for(auto i : ans) cout << fixed << setprecision(6) << i << " ";
	return 0;
}

Compilation message

Graph.cpp: In lambda function:
Graph.cpp:17:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |   for(auto [i, j] : g[v]) {
      |            ^
Graph.cpp: In lambda function:
Graph.cpp:26:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |     for(auto [k, w] : g[j]) {
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 500 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 452 KB answer = YES
4 Runtime error 1 ms 604 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 500 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 452 KB answer = YES
4 Runtime error 1 ms 604 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 500 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 452 KB answer = YES
4 Runtime error 1 ms 604 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 500 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 452 KB answer = YES
4 Runtime error 1 ms 604 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 500 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 452 KB answer = YES
4 Runtime error 1 ms 604 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -