답안 #859669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859669 2023-10-10T12:50:26 Z iskhakkutbilim Graph (BOI20_graph) C++17
34 / 100
302 ms 262144 KB
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
 
vector <vector <pair <int,int>>> g;
vector <int> used;
vector <int> comp;
 
void dfs(int v) {
	used[v] = 1;
	for(auto [i, j] : g[v]) {
		if(used[i] == LLONG_MAX) dfs(i);
	}
}
 
void get_comps() {
	for(int i = 0; i < used.size(); i ++) {
		if(used[i] == LLONG_MAX) {
			dfs(i);
			comp.push_back(i);
		}
	}
}
 
int check(int v) {
	int f = 1;
	for(auto [i, j] : g[v]) {
		if(used[i] == LLONG_MAX) {
			used[i] = j - used[v];
			f = min(f, check(i));
		}else {
			if(used[i] + used[v] != j) f = 0;
		}
	}
	return f;
}
 
vector <pair <int,int>> rec(int v) {
	int mn = LLONG_MAX;
	vector <pair <int,int>> ans;
	for(int val = -1000; val <= 1000; val += 1) {
		for(auto &j : used) j = LLONG_MAX;
		used[v] = val;
		if(check(v)) {
			int cnt = 0;
			for(auto &j : used) {
				if(j == LLONG_MAX) continue;
				cnt += abs(j);
			}
			if(cnt <= mn) {
				mn = cnt;
				for(int j = 0; j < used.size(); j ++) {
					if(used[j] == LLONG_MAX) continue;
					ans.push_back({j, used[j]});
				}
			}
		}
		// cout << val << " ";
		// if(val == 0.5) {
		// 	for(auto j : used) cout << j << " ";
		// }
	}
	if(mn == LLONG_MAX) {
		cout << "NO\n";
		exit(0);
	}
	return ans;
}
 
signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	g.resize(n);
	used.resize(n, LLONG_MAX);
 
	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*100});
		g[v].push_back({u, w*100});
	}
 
	get_comps();
	// assert(comp.size() < 2);
	for(auto &j : used) j = LLONG_MAX;
	vector <vector <pair <int,int>>> res;
	for(auto i : comp) {
		res.push_back(rec(i));
	}
	cout << "YES\n";
	vector <int> ans(n);
	for(auto i : res) {
		for(auto j : i) ans[j.first] = j.second;
	}
	for(auto i : ans) cout << fixed << setprecision(6) << (double)i*0.01 << " ";
	return 0;
}

Compilation message

Graph.cpp: In function 'void get_comps()':
Graph.cpp:19:19: 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]
   19 |  for(int i = 0; i < used.size(); i ++) {
      |                 ~~^~~~~~~~~~~~~
Graph.cpp: In function 'std::vector<std::pair<long long int, long long int> > rec(long long int)':
Graph.cpp:54:22: 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]
   54 |     for(int j = 0; j < used.size(); j ++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 344 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 604 KB answer = YES
6 Correct 1 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 1 ms 604 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 452 KB answer = YES
14 Correct 1 ms 600 KB answer = YES
15 Correct 1 ms 604 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 0 ms 460 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 500 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 344 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 604 KB answer = YES
6 Correct 1 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 1 ms 604 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 452 KB answer = YES
14 Correct 1 ms 600 KB answer = YES
15 Correct 1 ms 604 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 0 ms 460 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 500 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 4 ms 3540 KB answer = YES
25 Correct 3 ms 2264 KB answer = YES
26 Correct 5 ms 4076 KB answer = YES
27 Correct 2 ms 348 KB answer = YES
28 Correct 2 ms 348 KB answer = YES
29 Correct 5 ms 4684 KB answer = YES
30 Correct 2 ms 456 KB answer = NO
31 Correct 3 ms 2008 KB answer = YES
32 Correct 5 ms 464 KB answer = YES
33 Correct 12 ms 1884 KB answer = YES
34 Correct 7 ms 860 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 2 ms 348 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 344 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 604 KB answer = YES
6 Correct 1 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 1 ms 604 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 452 KB answer = YES
14 Correct 1 ms 600 KB answer = YES
15 Correct 1 ms 604 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 0 ms 460 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 500 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 4 ms 3540 KB answer = YES
25 Correct 3 ms 2264 KB answer = YES
26 Correct 5 ms 4076 KB answer = YES
27 Correct 2 ms 348 KB answer = YES
28 Correct 2 ms 348 KB answer = YES
29 Correct 5 ms 4684 KB answer = YES
30 Correct 2 ms 456 KB answer = NO
31 Correct 3 ms 2008 KB answer = YES
32 Correct 5 ms 464 KB answer = YES
33 Correct 12 ms 1884 KB answer = YES
34 Correct 7 ms 860 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 2 ms 348 KB answer = YES
37 Correct 8 ms 7120 KB answer = YES
38 Correct 3 ms 348 KB answer = YES
39 Correct 21 ms 21356 KB answer = YES
40 Correct 17 ms 600 KB answer = YES
41 Correct 16 ms 348 KB answer = NO
42 Correct 42 ms 42408 KB answer = YES
43 Correct 47 ms 26184 KB answer = YES
44 Correct 58 ms 26824 KB answer = YES
45 Correct 24 ms 344 KB answer = YES
46 Correct 34 ms 18868 KB answer = YES
47 Correct 20 ms 584 KB answer = YES
48 Correct 20 ms 612 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 344 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 604 KB answer = YES
6 Correct 1 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 1 ms 604 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 452 KB answer = YES
14 Correct 1 ms 600 KB answer = YES
15 Correct 1 ms 604 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 0 ms 460 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 500 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 4 ms 3540 KB answer = YES
25 Correct 3 ms 2264 KB answer = YES
26 Correct 5 ms 4076 KB answer = YES
27 Correct 2 ms 348 KB answer = YES
28 Correct 2 ms 348 KB answer = YES
29 Correct 5 ms 4684 KB answer = YES
30 Correct 2 ms 456 KB answer = NO
31 Correct 3 ms 2008 KB answer = YES
32 Correct 5 ms 464 KB answer = YES
33 Correct 12 ms 1884 KB answer = YES
34 Correct 7 ms 860 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 2 ms 348 KB answer = YES
37 Correct 8 ms 7120 KB answer = YES
38 Correct 3 ms 348 KB answer = YES
39 Correct 21 ms 21356 KB answer = YES
40 Correct 17 ms 600 KB answer = YES
41 Correct 16 ms 348 KB answer = NO
42 Correct 42 ms 42408 KB answer = YES
43 Correct 47 ms 26184 KB answer = YES
44 Correct 58 ms 26824 KB answer = YES
45 Correct 24 ms 344 KB answer = YES
46 Correct 34 ms 18868 KB answer = YES
47 Correct 20 ms 584 KB answer = YES
48 Correct 20 ms 612 KB answer = YES
49 Runtime error 302 ms 262144 KB Execution killed with signal 9
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 344 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Correct 0 ms 604 KB answer = YES
6 Correct 1 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 1 ms 604 KB answer = YES
9 Correct 0 ms 348 KB answer = NO
10 Correct 0 ms 348 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 452 KB answer = YES
14 Correct 1 ms 600 KB answer = YES
15 Correct 1 ms 604 KB answer = YES
16 Correct 0 ms 348 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 0 ms 344 KB answer = YES
19 Correct 0 ms 460 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 0 ms 500 KB answer = NO
23 Correct 0 ms 348 KB answer = NO
24 Correct 4 ms 3540 KB answer = YES
25 Correct 3 ms 2264 KB answer = YES
26 Correct 5 ms 4076 KB answer = YES
27 Correct 2 ms 348 KB answer = YES
28 Correct 2 ms 348 KB answer = YES
29 Correct 5 ms 4684 KB answer = YES
30 Correct 2 ms 456 KB answer = NO
31 Correct 3 ms 2008 KB answer = YES
32 Correct 5 ms 464 KB answer = YES
33 Correct 12 ms 1884 KB answer = YES
34 Correct 7 ms 860 KB answer = YES
35 Correct 1 ms 348 KB answer = YES
36 Correct 2 ms 348 KB answer = YES
37 Correct 8 ms 7120 KB answer = YES
38 Correct 3 ms 348 KB answer = YES
39 Correct 21 ms 21356 KB answer = YES
40 Correct 17 ms 600 KB answer = YES
41 Correct 16 ms 348 KB answer = NO
42 Correct 42 ms 42408 KB answer = YES
43 Correct 47 ms 26184 KB answer = YES
44 Correct 58 ms 26824 KB answer = YES
45 Correct 24 ms 344 KB answer = YES
46 Correct 34 ms 18868 KB answer = YES
47 Correct 20 ms 584 KB answer = YES
48 Correct 20 ms 612 KB answer = YES
49 Runtime error 302 ms 262144 KB Execution killed with signal 9
50 Halted 0 ms 0 KB -