# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
255075 |
2020-07-31T07:54:50 Z |
davitmarg |
Graph (BOI20_graph) |
C++17 |
|
198 ms |
28112 KB |
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int N = 200005;
int n, m,used[N],d[N];
LD val, a[N];
vector<pair<int, int>> g[N];
vector<pair<int,LD>> vals;
set<LD> x;
void dfs(int v)
{
vals.push_back(MP(v, a[v]));
used[v] = 1;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i].first;
int val = g[v][i].second;
if (used[to])
{
if (d[v] != d[to])
{
if (a[v] + a[to] != val)
{
cout << "NO" << endl;
exit(0);
}
}
else
{
LD X = (val - a[v] - a[to]) / 2.;
if (d[v] == 0)
x.insert(X);
else
x.insert(-X);
}
continue;
}
d[to] = d[v] ^ 1;
a[to] = val - a[v];
dfs(to);
}
}
int main()
{
fastIO;
cin >> n >> m;
while (m--)
{
int a, b, c;
cin >> a >> b >> c;
g[a].PB(MP(b, c));
g[b].PB(MP(a, c));
}
for (int i = 1; i <= n; i++)
{
if (used[i])
continue;
x.clear();
vals.clear();
dfs(i);
if (x.size() > 1)
{
cout << "NO" << endl;
exit(0);
}
LD X = 0;
if (!x.empty())
X = *x.begin();
else
{
for (int j = 0; j < vals.size(); j++)
if (!d[vals[j].first])
vals[j].second *= -1;
sort(all(vals), [](pair<int, LD> a, pair<int, LD> b) {
return a.second < b.second;
});
X = vals[vals.size() / 2].second;
}
for (int j = 0; j < vals.size(); j++)
if (!d[vals[j].first])
a[vals[j].first] += X;
else
a[vals[j].first] -= X;
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
/*
*/
Compilation message
Graph.cpp: In function 'void dfs(int)':
Graph.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++)
~~^~~~~~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:104:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < vals.size(); j++)
~~^~~~~~~~~~~~~
Graph.cpp:113:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < vals.size(); j++)
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
answer = YES |
2 |
Correct |
3 ms |
4992 KB |
answer = YES |
3 |
Correct |
3 ms |
4992 KB |
answer = YES |
4 |
Correct |
3 ms |
4992 KB |
answer = NO |
5 |
Correct |
3 ms |
4992 KB |
answer = YES |
6 |
Correct |
3 ms |
4992 KB |
answer = YES |
7 |
Correct |
3 ms |
4992 KB |
answer = YES |
8 |
Correct |
3 ms |
4992 KB |
answer = YES |
9 |
Correct |
3 ms |
4992 KB |
answer = NO |
10 |
Correct |
3 ms |
4992 KB |
answer = YES |
11 |
Correct |
3 ms |
4992 KB |
answer = YES |
12 |
Correct |
3 ms |
4992 KB |
answer = NO |
13 |
Correct |
3 ms |
4992 KB |
answer = YES |
14 |
Correct |
5 ms |
4992 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
3 ms |
4992 KB |
answer = YES |
17 |
Correct |
3 ms |
4992 KB |
answer = YES |
18 |
Correct |
4 ms |
4992 KB |
answer = YES |
19 |
Correct |
4 ms |
4992 KB |
answer = YES |
20 |
Correct |
4 ms |
4992 KB |
answer = YES |
21 |
Correct |
4 ms |
4992 KB |
answer = YES |
22 |
Correct |
3 ms |
4992 KB |
answer = NO |
23 |
Correct |
4 ms |
4992 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
answer = YES |
2 |
Correct |
3 ms |
4992 KB |
answer = YES |
3 |
Correct |
3 ms |
4992 KB |
answer = YES |
4 |
Correct |
3 ms |
4992 KB |
answer = NO |
5 |
Correct |
3 ms |
4992 KB |
answer = YES |
6 |
Correct |
3 ms |
4992 KB |
answer = YES |
7 |
Correct |
3 ms |
4992 KB |
answer = YES |
8 |
Correct |
3 ms |
4992 KB |
answer = YES |
9 |
Correct |
3 ms |
4992 KB |
answer = NO |
10 |
Correct |
3 ms |
4992 KB |
answer = YES |
11 |
Correct |
3 ms |
4992 KB |
answer = YES |
12 |
Correct |
3 ms |
4992 KB |
answer = NO |
13 |
Correct |
3 ms |
4992 KB |
answer = YES |
14 |
Correct |
5 ms |
4992 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
3 ms |
4992 KB |
answer = YES |
17 |
Correct |
3 ms |
4992 KB |
answer = YES |
18 |
Correct |
4 ms |
4992 KB |
answer = YES |
19 |
Correct |
4 ms |
4992 KB |
answer = YES |
20 |
Correct |
4 ms |
4992 KB |
answer = YES |
21 |
Correct |
4 ms |
4992 KB |
answer = YES |
22 |
Correct |
3 ms |
4992 KB |
answer = NO |
23 |
Correct |
4 ms |
4992 KB |
answer = NO |
24 |
Correct |
3 ms |
4992 KB |
answer = YES |
25 |
Correct |
4 ms |
4992 KB |
answer = YES |
26 |
Correct |
3 ms |
5120 KB |
answer = YES |
27 |
Correct |
3 ms |
5120 KB |
answer = YES |
28 |
Correct |
3 ms |
5120 KB |
answer = YES |
29 |
Correct |
3 ms |
5120 KB |
answer = YES |
30 |
Correct |
3 ms |
4992 KB |
answer = NO |
31 |
Correct |
3 ms |
4992 KB |
answer = YES |
32 |
Correct |
3 ms |
4992 KB |
answer = YES |
33 |
Correct |
3 ms |
4992 KB |
answer = YES |
34 |
Correct |
3 ms |
5120 KB |
answer = YES |
35 |
Correct |
3 ms |
4992 KB |
answer = YES |
36 |
Correct |
3 ms |
4992 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
answer = YES |
2 |
Correct |
3 ms |
4992 KB |
answer = YES |
3 |
Correct |
3 ms |
4992 KB |
answer = YES |
4 |
Correct |
3 ms |
4992 KB |
answer = NO |
5 |
Correct |
3 ms |
4992 KB |
answer = YES |
6 |
Correct |
3 ms |
4992 KB |
answer = YES |
7 |
Correct |
3 ms |
4992 KB |
answer = YES |
8 |
Correct |
3 ms |
4992 KB |
answer = YES |
9 |
Correct |
3 ms |
4992 KB |
answer = NO |
10 |
Correct |
3 ms |
4992 KB |
answer = YES |
11 |
Correct |
3 ms |
4992 KB |
answer = YES |
12 |
Correct |
3 ms |
4992 KB |
answer = NO |
13 |
Correct |
3 ms |
4992 KB |
answer = YES |
14 |
Correct |
5 ms |
4992 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
3 ms |
4992 KB |
answer = YES |
17 |
Correct |
3 ms |
4992 KB |
answer = YES |
18 |
Correct |
4 ms |
4992 KB |
answer = YES |
19 |
Correct |
4 ms |
4992 KB |
answer = YES |
20 |
Correct |
4 ms |
4992 KB |
answer = YES |
21 |
Correct |
4 ms |
4992 KB |
answer = YES |
22 |
Correct |
3 ms |
4992 KB |
answer = NO |
23 |
Correct |
4 ms |
4992 KB |
answer = NO |
24 |
Correct |
3 ms |
4992 KB |
answer = YES |
25 |
Correct |
4 ms |
4992 KB |
answer = YES |
26 |
Correct |
3 ms |
5120 KB |
answer = YES |
27 |
Correct |
3 ms |
5120 KB |
answer = YES |
28 |
Correct |
3 ms |
5120 KB |
answer = YES |
29 |
Correct |
3 ms |
5120 KB |
answer = YES |
30 |
Correct |
3 ms |
4992 KB |
answer = NO |
31 |
Correct |
3 ms |
4992 KB |
answer = YES |
32 |
Correct |
3 ms |
4992 KB |
answer = YES |
33 |
Correct |
3 ms |
4992 KB |
answer = YES |
34 |
Correct |
3 ms |
5120 KB |
answer = YES |
35 |
Correct |
3 ms |
4992 KB |
answer = YES |
36 |
Correct |
3 ms |
4992 KB |
answer = YES |
37 |
Correct |
3 ms |
5120 KB |
answer = YES |
38 |
Correct |
3 ms |
5120 KB |
answer = YES |
39 |
Correct |
3 ms |
5120 KB |
answer = YES |
40 |
Correct |
4 ms |
5248 KB |
answer = YES |
41 |
Correct |
3 ms |
5120 KB |
answer = NO |
42 |
Correct |
4 ms |
5248 KB |
answer = YES |
43 |
Correct |
6 ms |
5120 KB |
answer = YES |
44 |
Correct |
4 ms |
5120 KB |
answer = YES |
45 |
Correct |
6 ms |
5120 KB |
answer = YES |
46 |
Correct |
4 ms |
5120 KB |
answer = YES |
47 |
Correct |
6 ms |
5248 KB |
answer = YES |
48 |
Correct |
4 ms |
5248 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
answer = YES |
2 |
Correct |
3 ms |
4992 KB |
answer = YES |
3 |
Correct |
3 ms |
4992 KB |
answer = YES |
4 |
Correct |
3 ms |
4992 KB |
answer = NO |
5 |
Correct |
3 ms |
4992 KB |
answer = YES |
6 |
Correct |
3 ms |
4992 KB |
answer = YES |
7 |
Correct |
3 ms |
4992 KB |
answer = YES |
8 |
Correct |
3 ms |
4992 KB |
answer = YES |
9 |
Correct |
3 ms |
4992 KB |
answer = NO |
10 |
Correct |
3 ms |
4992 KB |
answer = YES |
11 |
Correct |
3 ms |
4992 KB |
answer = YES |
12 |
Correct |
3 ms |
4992 KB |
answer = NO |
13 |
Correct |
3 ms |
4992 KB |
answer = YES |
14 |
Correct |
5 ms |
4992 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
3 ms |
4992 KB |
answer = YES |
17 |
Correct |
3 ms |
4992 KB |
answer = YES |
18 |
Correct |
4 ms |
4992 KB |
answer = YES |
19 |
Correct |
4 ms |
4992 KB |
answer = YES |
20 |
Correct |
4 ms |
4992 KB |
answer = YES |
21 |
Correct |
4 ms |
4992 KB |
answer = YES |
22 |
Correct |
3 ms |
4992 KB |
answer = NO |
23 |
Correct |
4 ms |
4992 KB |
answer = NO |
24 |
Correct |
3 ms |
4992 KB |
answer = YES |
25 |
Correct |
4 ms |
4992 KB |
answer = YES |
26 |
Correct |
3 ms |
5120 KB |
answer = YES |
27 |
Correct |
3 ms |
5120 KB |
answer = YES |
28 |
Correct |
3 ms |
5120 KB |
answer = YES |
29 |
Correct |
3 ms |
5120 KB |
answer = YES |
30 |
Correct |
3 ms |
4992 KB |
answer = NO |
31 |
Correct |
3 ms |
4992 KB |
answer = YES |
32 |
Correct |
3 ms |
4992 KB |
answer = YES |
33 |
Correct |
3 ms |
4992 KB |
answer = YES |
34 |
Correct |
3 ms |
5120 KB |
answer = YES |
35 |
Correct |
3 ms |
4992 KB |
answer = YES |
36 |
Correct |
3 ms |
4992 KB |
answer = YES |
37 |
Correct |
3 ms |
5120 KB |
answer = YES |
38 |
Correct |
3 ms |
5120 KB |
answer = YES |
39 |
Correct |
3 ms |
5120 KB |
answer = YES |
40 |
Correct |
4 ms |
5248 KB |
answer = YES |
41 |
Correct |
3 ms |
5120 KB |
answer = NO |
42 |
Correct |
4 ms |
5248 KB |
answer = YES |
43 |
Correct |
6 ms |
5120 KB |
answer = YES |
44 |
Correct |
4 ms |
5120 KB |
answer = YES |
45 |
Correct |
6 ms |
5120 KB |
answer = YES |
46 |
Correct |
4 ms |
5120 KB |
answer = YES |
47 |
Correct |
6 ms |
5248 KB |
answer = YES |
48 |
Correct |
4 ms |
5248 KB |
answer = YES |
49 |
Correct |
13 ms |
6272 KB |
answer = YES |
50 |
Correct |
13 ms |
6780 KB |
answer = YES |
51 |
Correct |
13 ms |
6908 KB |
answer = YES |
52 |
Correct |
7 ms |
5760 KB |
answer = NO |
53 |
Correct |
4 ms |
5120 KB |
answer = YES |
54 |
Correct |
5 ms |
5376 KB |
answer = YES |
55 |
Correct |
8 ms |
5760 KB |
answer = YES |
56 |
Correct |
12 ms |
6268 KB |
answer = YES |
57 |
Correct |
12 ms |
5888 KB |
answer = YES |
58 |
Correct |
11 ms |
6016 KB |
answer = YES |
59 |
Correct |
11 ms |
6016 KB |
answer = YES |
60 |
Correct |
14 ms |
6016 KB |
answer = YES |
61 |
Correct |
8 ms |
5756 KB |
answer = YES |
62 |
Correct |
60 ms |
9960 KB |
answer = NO |
63 |
Correct |
70 ms |
11128 KB |
answer = YES |
64 |
Correct |
66 ms |
11120 KB |
answer = NO |
65 |
Correct |
78 ms |
11064 KB |
answer = YES |
66 |
Correct |
8 ms |
5248 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
answer = YES |
2 |
Correct |
3 ms |
4992 KB |
answer = YES |
3 |
Correct |
3 ms |
4992 KB |
answer = YES |
4 |
Correct |
3 ms |
4992 KB |
answer = NO |
5 |
Correct |
3 ms |
4992 KB |
answer = YES |
6 |
Correct |
3 ms |
4992 KB |
answer = YES |
7 |
Correct |
3 ms |
4992 KB |
answer = YES |
8 |
Correct |
3 ms |
4992 KB |
answer = YES |
9 |
Correct |
3 ms |
4992 KB |
answer = NO |
10 |
Correct |
3 ms |
4992 KB |
answer = YES |
11 |
Correct |
3 ms |
4992 KB |
answer = YES |
12 |
Correct |
3 ms |
4992 KB |
answer = NO |
13 |
Correct |
3 ms |
4992 KB |
answer = YES |
14 |
Correct |
5 ms |
4992 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
3 ms |
4992 KB |
answer = YES |
17 |
Correct |
3 ms |
4992 KB |
answer = YES |
18 |
Correct |
4 ms |
4992 KB |
answer = YES |
19 |
Correct |
4 ms |
4992 KB |
answer = YES |
20 |
Correct |
4 ms |
4992 KB |
answer = YES |
21 |
Correct |
4 ms |
4992 KB |
answer = YES |
22 |
Correct |
3 ms |
4992 KB |
answer = NO |
23 |
Correct |
4 ms |
4992 KB |
answer = NO |
24 |
Correct |
3 ms |
4992 KB |
answer = YES |
25 |
Correct |
4 ms |
4992 KB |
answer = YES |
26 |
Correct |
3 ms |
5120 KB |
answer = YES |
27 |
Correct |
3 ms |
5120 KB |
answer = YES |
28 |
Correct |
3 ms |
5120 KB |
answer = YES |
29 |
Correct |
3 ms |
5120 KB |
answer = YES |
30 |
Correct |
3 ms |
4992 KB |
answer = NO |
31 |
Correct |
3 ms |
4992 KB |
answer = YES |
32 |
Correct |
3 ms |
4992 KB |
answer = YES |
33 |
Correct |
3 ms |
4992 KB |
answer = YES |
34 |
Correct |
3 ms |
5120 KB |
answer = YES |
35 |
Correct |
3 ms |
4992 KB |
answer = YES |
36 |
Correct |
3 ms |
4992 KB |
answer = YES |
37 |
Correct |
3 ms |
5120 KB |
answer = YES |
38 |
Correct |
3 ms |
5120 KB |
answer = YES |
39 |
Correct |
3 ms |
5120 KB |
answer = YES |
40 |
Correct |
4 ms |
5248 KB |
answer = YES |
41 |
Correct |
3 ms |
5120 KB |
answer = NO |
42 |
Correct |
4 ms |
5248 KB |
answer = YES |
43 |
Correct |
6 ms |
5120 KB |
answer = YES |
44 |
Correct |
4 ms |
5120 KB |
answer = YES |
45 |
Correct |
6 ms |
5120 KB |
answer = YES |
46 |
Correct |
4 ms |
5120 KB |
answer = YES |
47 |
Correct |
6 ms |
5248 KB |
answer = YES |
48 |
Correct |
4 ms |
5248 KB |
answer = YES |
49 |
Correct |
13 ms |
6272 KB |
answer = YES |
50 |
Correct |
13 ms |
6780 KB |
answer = YES |
51 |
Correct |
13 ms |
6908 KB |
answer = YES |
52 |
Correct |
7 ms |
5760 KB |
answer = NO |
53 |
Correct |
4 ms |
5120 KB |
answer = YES |
54 |
Correct |
5 ms |
5376 KB |
answer = YES |
55 |
Correct |
8 ms |
5760 KB |
answer = YES |
56 |
Correct |
12 ms |
6268 KB |
answer = YES |
57 |
Correct |
12 ms |
5888 KB |
answer = YES |
58 |
Correct |
11 ms |
6016 KB |
answer = YES |
59 |
Correct |
11 ms |
6016 KB |
answer = YES |
60 |
Correct |
14 ms |
6016 KB |
answer = YES |
61 |
Correct |
8 ms |
5756 KB |
answer = YES |
62 |
Correct |
60 ms |
9960 KB |
answer = NO |
63 |
Correct |
70 ms |
11128 KB |
answer = YES |
64 |
Correct |
66 ms |
11120 KB |
answer = NO |
65 |
Correct |
78 ms |
11064 KB |
answer = YES |
66 |
Correct |
8 ms |
5248 KB |
answer = YES |
67 |
Correct |
107 ms |
25052 KB |
answer = YES |
68 |
Correct |
102 ms |
24924 KB |
answer = YES |
69 |
Correct |
95 ms |
24928 KB |
answer = YES |
70 |
Correct |
138 ms |
28112 KB |
answer = YES |
71 |
Correct |
101 ms |
25180 KB |
answer = YES |
72 |
Correct |
167 ms |
15336 KB |
answer = YES |
73 |
Correct |
142 ms |
15464 KB |
answer = YES |
74 |
Correct |
74 ms |
16616 KB |
answer = YES |
75 |
Correct |
34 ms |
12396 KB |
answer = NO |
76 |
Correct |
14 ms |
6396 KB |
answer = YES |
77 |
Correct |
45 ms |
7668 KB |
answer = YES |
78 |
Correct |
58 ms |
9840 KB |
answer = YES |
79 |
Correct |
100 ms |
14444 KB |
answer = YES |
80 |
Correct |
85 ms |
16612 KB |
answer = YES |
81 |
Correct |
71 ms |
19432 KB |
answer = NO |
82 |
Correct |
140 ms |
24284 KB |
answer = YES |
83 |
Correct |
140 ms |
25180 KB |
answer = YES |
84 |
Correct |
155 ms |
25220 KB |
answer = YES |
85 |
Correct |
118 ms |
25180 KB |
answer = YES |
86 |
Correct |
105 ms |
25052 KB |
answer = YES |
87 |
Correct |
87 ms |
14704 KB |
answer = NO |
88 |
Correct |
161 ms |
17124 KB |
answer = YES |
89 |
Correct |
104 ms |
10872 KB |
answer = YES |
90 |
Correct |
97 ms |
10872 KB |
answer = YES |
91 |
Correct |
104 ms |
10872 KB |
answer = YES |
92 |
Correct |
53 ms |
10224 KB |
answer = YES |
93 |
Correct |
63 ms |
10224 KB |
answer = YES |
94 |
Correct |
76 ms |
24800 KB |
answer = NO |
95 |
Correct |
52 ms |
10488 KB |
answer = NO |
96 |
Correct |
198 ms |
24044 KB |
answer = YES |
97 |
Correct |
53 ms |
24804 KB |
answer = NO |