답안 #859414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859414 2023-10-10T06:11:26 Z iskhakkutbilim Graph (BOI20_graph) C++17
0 / 100
2 ms 7516 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;

int n, m;
vector< pair<int, long double> > g[N+10];
int used[N+10];
long double cost[N+10];
long double sum;
void dfs(int v){
	used[v] = 1;
	sum+= abs(cost[v]);
	for(auto [to, c] : g[v]){
		if(used[to] == 0){
			cost[to] = c - cost[v];
			dfs(to);
		}else{
			
		}
	}
}

main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   long double  ans = 1e18;
	cin >> n >> m;
	for(int i = 0;i < m; i++){
		int a, b, c; cin >> a >> b >> c;
		g[a].push_back({b, (long double)c * 10.0});
		g[b].push_back({a, (long double)c * 10.0});
	}
	vector<long double> how(n + 1);
	for(int start = -100; start <= 100; start++){
		for(int i = 1;i <= n; i++){
			for(int j = 1;j <= n; j++) used[j] = 0;
			sum = 0;
			cost[i] = start;
			dfs(i);
			int ok = 1;
			for(int v = 1; v <= n && ok; v++){
				for(auto [to, c] : g[v]){
					if(cost[v] + cost[to] != c){
						ok = 0;
						break;
					}
				}
			}
			if(ans > sum && ok){
				ans = sum;
				for(int j = 1;j <= n; j++) how[j] = cost[j];
			}
		}
	}
	if(ans >= 1e18){
		cout << "NO";
		return 0;
	}
	cout << "YES" << '\n';
	cout << fixed << setprecision(6);
	for(int i = 1;i <= n; i++) cout << how[i] / 10 << ' ';
	return 0;
}

Compilation message

Graph.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB answer = YES
2 Correct 2 ms 7516 KB answer = YES
3 Correct 2 ms 7516 KB answer = YES
4 Correct 2 ms 7516 KB answer = NO
5 Correct 2 ms 7516 KB answer = YES
6 Correct 2 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 2 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 2 ms 7516 KB answer = YES
11 Correct 2 ms 7516 KB answer = YES
12 Correct 2 ms 7516 KB answer = NO
13 Correct 2 ms 7516 KB answer = YES
14 Correct 2 ms 7516 KB answer = YES
15 Correct 2 ms 7516 KB answer = YES
16 Correct 2 ms 7516 KB answer = YES
17 Correct 2 ms 7516 KB answer = YES
18 Correct 2 ms 7516 KB answer = YES
19 Incorrect 1 ms 7516 KB jury has the better answer: jans = YES, pans = NO
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB answer = YES
2 Correct 2 ms 7516 KB answer = YES
3 Correct 2 ms 7516 KB answer = YES
4 Correct 2 ms 7516 KB answer = NO
5 Correct 2 ms 7516 KB answer = YES
6 Correct 2 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 2 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 2 ms 7516 KB answer = YES
11 Correct 2 ms 7516 KB answer = YES
12 Correct 2 ms 7516 KB answer = NO
13 Correct 2 ms 7516 KB answer = YES
14 Correct 2 ms 7516 KB answer = YES
15 Correct 2 ms 7516 KB answer = YES
16 Correct 2 ms 7516 KB answer = YES
17 Correct 2 ms 7516 KB answer = YES
18 Correct 2 ms 7516 KB answer = YES
19 Incorrect 1 ms 7516 KB jury has the better answer: jans = YES, pans = NO
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB answer = YES
2 Correct 2 ms 7516 KB answer = YES
3 Correct 2 ms 7516 KB answer = YES
4 Correct 2 ms 7516 KB answer = NO
5 Correct 2 ms 7516 KB answer = YES
6 Correct 2 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 2 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 2 ms 7516 KB answer = YES
11 Correct 2 ms 7516 KB answer = YES
12 Correct 2 ms 7516 KB answer = NO
13 Correct 2 ms 7516 KB answer = YES
14 Correct 2 ms 7516 KB answer = YES
15 Correct 2 ms 7516 KB answer = YES
16 Correct 2 ms 7516 KB answer = YES
17 Correct 2 ms 7516 KB answer = YES
18 Correct 2 ms 7516 KB answer = YES
19 Incorrect 1 ms 7516 KB jury has the better answer: jans = YES, pans = NO
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB answer = YES
2 Correct 2 ms 7516 KB answer = YES
3 Correct 2 ms 7516 KB answer = YES
4 Correct 2 ms 7516 KB answer = NO
5 Correct 2 ms 7516 KB answer = YES
6 Correct 2 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 2 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 2 ms 7516 KB answer = YES
11 Correct 2 ms 7516 KB answer = YES
12 Correct 2 ms 7516 KB answer = NO
13 Correct 2 ms 7516 KB answer = YES
14 Correct 2 ms 7516 KB answer = YES
15 Correct 2 ms 7516 KB answer = YES
16 Correct 2 ms 7516 KB answer = YES
17 Correct 2 ms 7516 KB answer = YES
18 Correct 2 ms 7516 KB answer = YES
19 Incorrect 1 ms 7516 KB jury has the better answer: jans = YES, pans = NO
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB answer = YES
2 Correct 2 ms 7516 KB answer = YES
3 Correct 2 ms 7516 KB answer = YES
4 Correct 2 ms 7516 KB answer = NO
5 Correct 2 ms 7516 KB answer = YES
6 Correct 2 ms 7516 KB answer = YES
7 Correct 1 ms 7516 KB answer = YES
8 Correct 2 ms 7516 KB answer = YES
9 Correct 2 ms 7516 KB answer = NO
10 Correct 2 ms 7516 KB answer = YES
11 Correct 2 ms 7516 KB answer = YES
12 Correct 2 ms 7516 KB answer = NO
13 Correct 2 ms 7516 KB answer = YES
14 Correct 2 ms 7516 KB answer = YES
15 Correct 2 ms 7516 KB answer = YES
16 Correct 2 ms 7516 KB answer = YES
17 Correct 2 ms 7516 KB answer = YES
18 Correct 2 ms 7516 KB answer = YES
19 Incorrect 1 ms 7516 KB jury has the better answer: jans = YES, pans = NO
20 Halted 0 ms 0 KB -