Submission #291900

# Submission time Handle Problem Language Result Execution time Memory
291900 2020-09-06T01:03:48 Z Berted Graph (BOI20_graph) C++14
100 / 100
202 ms 20924 KB
#include <iostream>
#include <bitset>
#include <iomanip>
#include <assert.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
 
#define vi vector<int>
#define pub push_back
#define pii pair<int, int>
#define fst first
#define snd second
#define vpi vector<pii>

const int INF = 1e9;

using namespace std;
 
int n, m, res[100001], sgn[100001], c[100001];
vpi adj[100001];
bitset<100001> vis;
vector<int> lol, mem;
int k = INF;

void dfs(int u)
{
	if (sgn[u]) {lol.push_back(c[u]);}
	else {lol.push_back(-c[u]);}
	mem.push_back(u);
	for (auto v : adj[u])
	{
		if (!vis[v.fst])
		{
			vis[v.fst] = 1;
			sgn[v.fst] = !sgn[u];
			c[v.fst] = 2 * v.snd - c[u];
			dfs(v.fst);
		}
		else
		{
			if (sgn[v.fst] != sgn[u] && c[v.fst] == 2 * v.snd - c[u]) continue;
			else if (sgn[v.fst] == sgn[u]) 
			{
				int r;
				if (sgn[v.fst])
				{
					r = c[v.fst] - (2 * v.snd - c[u]);
				}
				else
				{
					r = (2 * v.snd - c[u]) - c[v.fst];
				}
				r /= 2;
				if (k == INF || k == r) {k = r;}
				else {k = -INF;}
			}
			else {k = -INF;}
		}
	}
}
 

 
int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {res[i] = 1000000;}
	for (int i = 0; i < m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		adj[u - 1].push_back({v - 1, w});
		adj[v - 1].push_back({u - 1, w});
	}
	bool val = 1;
	for (int i = 0; i < n && val; i++)
	{
		if (!vis[i])
		{
			vis[i] = 1; sgn[i] = 0; c[i] = 0;
			dfs(i);
			if (k == INF) 
			{
				nth_element(lol.begin(), lol.begin() + lol.size() / 2, lol.end());
				k = lol[lol.size() / 2];
			}
			if (k == -INF) {val = 0;}
			else
			{
				for (auto x : mem)
				{
					res[x] = c[x] + ((sgn[x]) ? (-k) : k);
				}
			}
			lol.clear();
			mem.clear();
			k = INF;
		}
	}
	if (val)
	{
		cout << "YES\n";
		for (int i = 0; i < n; i++)
		{
			cout << fixed << setprecision(6) << (double)res[i] / 2;
			if (i + 1 < n) cout << " ";
		}
		cout << "\n";
	}
	else {cout << "NO\n";}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2688 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2688 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2688 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
37 Correct 3 ms 2720 KB answer = YES
38 Correct 2 ms 2688 KB answer = YES
39 Correct 3 ms 2816 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 2 ms 2816 KB answer = NO
42 Correct 3 ms 2816 KB answer = YES
43 Correct 3 ms 2816 KB answer = YES
44 Correct 3 ms 2816 KB answer = YES
45 Correct 3 ms 2816 KB answer = YES
46 Correct 3 ms 2816 KB answer = YES
47 Correct 3 ms 2816 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2688 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
37 Correct 3 ms 2720 KB answer = YES
38 Correct 2 ms 2688 KB answer = YES
39 Correct 3 ms 2816 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 2 ms 2816 KB answer = NO
42 Correct 3 ms 2816 KB answer = YES
43 Correct 3 ms 2816 KB answer = YES
44 Correct 3 ms 2816 KB answer = YES
45 Correct 3 ms 2816 KB answer = YES
46 Correct 3 ms 2816 KB answer = YES
47 Correct 3 ms 2816 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
49 Correct 11 ms 3584 KB answer = YES
50 Correct 12 ms 3840 KB answer = YES
51 Correct 12 ms 3840 KB answer = YES
52 Correct 7 ms 3712 KB answer = NO
53 Correct 3 ms 2816 KB answer = YES
54 Correct 4 ms 2944 KB answer = YES
55 Correct 7 ms 3200 KB answer = YES
56 Correct 11 ms 3584 KB answer = YES
57 Correct 11 ms 3456 KB answer = YES
58 Correct 10 ms 3456 KB answer = YES
59 Correct 10 ms 3456 KB answer = YES
60 Correct 11 ms 3456 KB answer = YES
61 Correct 7 ms 3200 KB answer = YES
62 Correct 72 ms 10232 KB answer = NO
63 Correct 75 ms 10360 KB answer = YES
64 Correct 73 ms 10232 KB answer = NO
65 Correct 75 ms 10360 KB answer = YES
66 Correct 4 ms 2816 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2688 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
37 Correct 3 ms 2720 KB answer = YES
38 Correct 2 ms 2688 KB answer = YES
39 Correct 3 ms 2816 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 2 ms 2816 KB answer = NO
42 Correct 3 ms 2816 KB answer = YES
43 Correct 3 ms 2816 KB answer = YES
44 Correct 3 ms 2816 KB answer = YES
45 Correct 3 ms 2816 KB answer = YES
46 Correct 3 ms 2816 KB answer = YES
47 Correct 3 ms 2816 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
49 Correct 11 ms 3584 KB answer = YES
50 Correct 12 ms 3840 KB answer = YES
51 Correct 12 ms 3840 KB answer = YES
52 Correct 7 ms 3712 KB answer = NO
53 Correct 3 ms 2816 KB answer = YES
54 Correct 4 ms 2944 KB answer = YES
55 Correct 7 ms 3200 KB answer = YES
56 Correct 11 ms 3584 KB answer = YES
57 Correct 11 ms 3456 KB answer = YES
58 Correct 10 ms 3456 KB answer = YES
59 Correct 10 ms 3456 KB answer = YES
60 Correct 11 ms 3456 KB answer = YES
61 Correct 7 ms 3200 KB answer = YES
62 Correct 72 ms 10232 KB answer = NO
63 Correct 75 ms 10360 KB answer = YES
64 Correct 73 ms 10232 KB answer = NO
65 Correct 75 ms 10360 KB answer = YES
66 Correct 4 ms 2816 KB answer = YES
67 Correct 101 ms 16616 KB answer = YES
68 Correct 90 ms 16492 KB answer = YES
69 Correct 95 ms 16492 KB answer = YES
70 Correct 131 ms 20924 KB answer = YES
71 Correct 96 ms 16620 KB answer = YES
72 Correct 119 ms 10856 KB answer = YES
73 Correct 116 ms 10984 KB answer = YES
74 Correct 76 ms 10912 KB answer = YES
75 Correct 34 ms 10272 KB answer = NO
76 Correct 13 ms 3712 KB answer = YES
77 Correct 33 ms 4728 KB answer = YES
78 Correct 46 ms 6520 KB answer = YES
79 Correct 95 ms 9708 KB answer = YES
80 Correct 74 ms 10912 KB answer = YES
81 Correct 56 ms 12656 KB answer = NO
82 Correct 116 ms 16108 KB answer = YES
83 Correct 143 ms 16748 KB answer = YES
84 Correct 136 ms 16748 KB answer = YES
85 Correct 100 ms 16620 KB answer = YES
86 Correct 104 ms 16616 KB answer = YES
87 Correct 69 ms 10488 KB answer = NO
88 Correct 136 ms 12532 KB answer = YES
89 Correct 104 ms 9208 KB answer = YES
90 Correct 100 ms 9208 KB answer = YES
91 Correct 112 ms 9208 KB answer = YES
92 Correct 52 ms 6900 KB answer = YES
93 Correct 50 ms 6900 KB answer = YES
94 Correct 77 ms 15596 KB answer = NO
95 Correct 53 ms 8312 KB answer = NO
96 Correct 202 ms 18412 KB answer = YES
97 Correct 44 ms 15596 KB answer = NO