답안 #859365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859365 2023-10-10T05:07:01 Z maks007 Graph (BOI20_graph) C++14
0 / 100
1 ms 348 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;
	vector <int> v;
	function<void(int)> dfs=[&](int v) {
		node[v] = 0;
		for(auto [i, j] : g[v]) {
			if(!node[i]) continue;
			dfs(i);
		}
	};
	function <int(int,double)> check=[&](int v, double color) {
		node[v] = color;
		// cout << v << " " << color << "\n";
		int f = 1;
		for(auto [i,j] : g[v]) {
			if(node[i] == 1e9) f = min(f, check(i, j-color));
			else {
				if(node[v] + node[i] != j) f = 0;
			} 
		}
		return f;
	};
	function<void(int, int)> rec=[&](int i, int sum) {
		if(i == v.size()) {
			if(mn > sum) {
				mn = sum;
				ans = node;
			}	
			return;
		}
		for(double val = -2; val <= 2; val += 0.125) {
			for(auto &j : node) j = 1e9;
			if(check(v[i], val)) {
				// cout << val << " " << i << "\n";
				node[v[i]] = val;
				rec(i + 1, sum + fabs(val));
				node[v[i]] = 1e9;
			}
				// cout << "\n";
		}
	};
	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});
	}
	for(int i = 0; i < n; i ++) {
		if(node[i] == 1e9) {dfs(i);v.push_back(i);}
	}
	// for(auto i : v) cout << i << " ";
	for(auto &j : node) j = 1e9;
	rec(0, 0);
	if(mn == 1e9) cout << "NO";
	else {
		cout << "YES\n";
		for(auto i : ans) cout << fixed << setprecision(6) << i << " ";
	}
	return 0;
}

Compilation message

Graph.cpp: In lambda function:
Graph.cpp:18:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |   for(auto [i, j] : g[v]) {
      |            ^
Graph.cpp: In lambda function:
Graph.cpp:27:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |   for(auto [i,j] : g[v]) {
      |            ^
Graph.cpp: In lambda function:
Graph.cpp:36:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   if(i == v.size()) {
      |      ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Incorrect 1 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Incorrect 1 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Incorrect 1 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Incorrect 1 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Incorrect 1 ms 348 KB participant answer is larger than the answer of jury
3 Halted 0 ms 0 KB -