# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1110460 |
2024-11-09T13:52:15 Z |
LucasLe |
Graph (BOI20_graph) |
C++17 |
|
132 ms |
27584 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> edge;
typedef pair<ll,ll> node;
const int maxn = 200001;
bool vis[maxn];
node val[maxn];
db ans[maxn];
vector<edge>G[maxn];
bool flag, found;
node x;
const db eps = 1e-8;
vector<int> cur;
void dfs(int u, int p){
vis[u] = 1;
cur.push_back(u);
for(auto v:G[u]){
if(v.first == p) continue;
node t = {val[u].first * -1ll, v.second - val[u].second};
if(!vis[v.first]){
val[v.first] = t;
dfs(v.first, u);
} else{
if(t.first == val[v.first].first){
if(t.second != val[v.first].second){
flag = false;
return;
}
} else{
node tx = {t.first - val[v.first].first, val[v.first].second - t.second};
if(!found) x = tx, found = 1;
else if(x.first * tx.second != x.second * tx.first){
flag = false;
return;
}
}
}
}
}
db f(db xx){
db res = 0;
for(int u:cur)
res += fabs(xx * (db)val[u].first + (db)val[u].second);
return res;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(7);
int n, m;
cin >> n >> m;
while(m--){
int u, v, c;
cin >> u >> v >> c;
G[u].push_back({v,c});
G[v].push_back({u,c});
}
flag = true;
for(int i = 1; i <= n && flag; i++)
if(!vis[i]){
val[i] = {1,0};
found = false;
cur.clear();
dfs(i,-1);
db xx = 0;
if(found)
xx = (db)x.second/(db)x.first;
else{
db l = -20000000000, r = 20000000000;
while(fabs(r - l) > eps){
db m1 = l + (r-l)/(db)3;
db m2 = r - (r-l)/(db)3;
if(f(m1) > f(m2))
l = m1;
else
r = m2;
}
xx = l;
}
for(int u:cur)
ans[u] = xx * (db)val[u].first + (db)val[u].second;
}
if(!flag){
cout << "NO";
return 0;
}
cout << "YES\n";
for(int i = 1; i <= n; i++)
cout << ans[i] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
answer = YES |
2 |
Correct |
2 ms |
8784 KB |
answer = YES |
3 |
Correct |
2 ms |
8784 KB |
answer = YES |
4 |
Correct |
2 ms |
8784 KB |
answer = NO |
5 |
Correct |
2 ms |
8784 KB |
answer = YES |
6 |
Correct |
2 ms |
8784 KB |
answer = YES |
7 |
Correct |
3 ms |
8784 KB |
answer = YES |
8 |
Correct |
2 ms |
8784 KB |
answer = YES |
9 |
Correct |
2 ms |
8784 KB |
answer = NO |
10 |
Correct |
2 ms |
8952 KB |
answer = YES |
11 |
Correct |
2 ms |
8784 KB |
answer = YES |
12 |
Correct |
2 ms |
8784 KB |
answer = NO |
13 |
Correct |
2 ms |
8784 KB |
answer = YES |
14 |
Correct |
2 ms |
8784 KB |
answer = YES |
15 |
Correct |
2 ms |
8784 KB |
answer = YES |
16 |
Correct |
2 ms |
8784 KB |
answer = YES |
17 |
Correct |
2 ms |
8848 KB |
answer = YES |
18 |
Correct |
2 ms |
8952 KB |
answer = YES |
19 |
Correct |
2 ms |
8784 KB |
answer = YES |
20 |
Correct |
2 ms |
8784 KB |
answer = YES |
21 |
Correct |
2 ms |
8784 KB |
answer = YES |
22 |
Correct |
2 ms |
8784 KB |
answer = NO |
23 |
Correct |
2 ms |
8784 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
answer = YES |
2 |
Correct |
2 ms |
8784 KB |
answer = YES |
3 |
Correct |
2 ms |
8784 KB |
answer = YES |
4 |
Correct |
2 ms |
8784 KB |
answer = NO |
5 |
Correct |
2 ms |
8784 KB |
answer = YES |
6 |
Correct |
2 ms |
8784 KB |
answer = YES |
7 |
Correct |
3 ms |
8784 KB |
answer = YES |
8 |
Correct |
2 ms |
8784 KB |
answer = YES |
9 |
Correct |
2 ms |
8784 KB |
answer = NO |
10 |
Correct |
2 ms |
8952 KB |
answer = YES |
11 |
Correct |
2 ms |
8784 KB |
answer = YES |
12 |
Correct |
2 ms |
8784 KB |
answer = NO |
13 |
Correct |
2 ms |
8784 KB |
answer = YES |
14 |
Correct |
2 ms |
8784 KB |
answer = YES |
15 |
Correct |
2 ms |
8784 KB |
answer = YES |
16 |
Correct |
2 ms |
8784 KB |
answer = YES |
17 |
Correct |
2 ms |
8848 KB |
answer = YES |
18 |
Correct |
2 ms |
8952 KB |
answer = YES |
19 |
Correct |
2 ms |
8784 KB |
answer = YES |
20 |
Correct |
2 ms |
8784 KB |
answer = YES |
21 |
Correct |
2 ms |
8784 KB |
answer = YES |
22 |
Correct |
2 ms |
8784 KB |
answer = NO |
23 |
Correct |
2 ms |
8784 KB |
answer = NO |
24 |
Correct |
2 ms |
8784 KB |
answer = YES |
25 |
Correct |
2 ms |
8784 KB |
answer = YES |
26 |
Correct |
2 ms |
8784 KB |
answer = YES |
27 |
Correct |
2 ms |
8784 KB |
answer = YES |
28 |
Correct |
2 ms |
8784 KB |
answer = YES |
29 |
Correct |
2 ms |
8952 KB |
answer = YES |
30 |
Correct |
2 ms |
8784 KB |
answer = NO |
31 |
Correct |
2 ms |
8784 KB |
answer = YES |
32 |
Correct |
2 ms |
8784 KB |
answer = YES |
33 |
Correct |
2 ms |
8784 KB |
answer = YES |
34 |
Correct |
2 ms |
8784 KB |
answer = YES |
35 |
Correct |
2 ms |
8784 KB |
answer = YES |
36 |
Correct |
2 ms |
8784 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
answer = YES |
2 |
Correct |
2 ms |
8784 KB |
answer = YES |
3 |
Correct |
2 ms |
8784 KB |
answer = YES |
4 |
Correct |
2 ms |
8784 KB |
answer = NO |
5 |
Correct |
2 ms |
8784 KB |
answer = YES |
6 |
Correct |
2 ms |
8784 KB |
answer = YES |
7 |
Correct |
3 ms |
8784 KB |
answer = YES |
8 |
Correct |
2 ms |
8784 KB |
answer = YES |
9 |
Correct |
2 ms |
8784 KB |
answer = NO |
10 |
Correct |
2 ms |
8952 KB |
answer = YES |
11 |
Correct |
2 ms |
8784 KB |
answer = YES |
12 |
Correct |
2 ms |
8784 KB |
answer = NO |
13 |
Correct |
2 ms |
8784 KB |
answer = YES |
14 |
Correct |
2 ms |
8784 KB |
answer = YES |
15 |
Correct |
2 ms |
8784 KB |
answer = YES |
16 |
Correct |
2 ms |
8784 KB |
answer = YES |
17 |
Correct |
2 ms |
8848 KB |
answer = YES |
18 |
Correct |
2 ms |
8952 KB |
answer = YES |
19 |
Correct |
2 ms |
8784 KB |
answer = YES |
20 |
Correct |
2 ms |
8784 KB |
answer = YES |
21 |
Correct |
2 ms |
8784 KB |
answer = YES |
22 |
Correct |
2 ms |
8784 KB |
answer = NO |
23 |
Correct |
2 ms |
8784 KB |
answer = NO |
24 |
Correct |
2 ms |
8784 KB |
answer = YES |
25 |
Correct |
2 ms |
8784 KB |
answer = YES |
26 |
Correct |
2 ms |
8784 KB |
answer = YES |
27 |
Correct |
2 ms |
8784 KB |
answer = YES |
28 |
Correct |
2 ms |
8784 KB |
answer = YES |
29 |
Correct |
2 ms |
8952 KB |
answer = YES |
30 |
Correct |
2 ms |
8784 KB |
answer = NO |
31 |
Correct |
2 ms |
8784 KB |
answer = YES |
32 |
Correct |
2 ms |
8784 KB |
answer = YES |
33 |
Correct |
2 ms |
8784 KB |
answer = YES |
34 |
Correct |
2 ms |
8784 KB |
answer = YES |
35 |
Correct |
2 ms |
8784 KB |
answer = YES |
36 |
Correct |
2 ms |
8784 KB |
answer = YES |
37 |
Correct |
2 ms |
8784 KB |
answer = YES |
38 |
Correct |
2 ms |
8784 KB |
answer = YES |
39 |
Correct |
2 ms |
8796 KB |
answer = YES |
40 |
Correct |
2 ms |
8784 KB |
answer = YES |
41 |
Correct |
2 ms |
8808 KB |
answer = NO |
42 |
Correct |
3 ms |
8784 KB |
answer = YES |
43 |
Correct |
3 ms |
8784 KB |
answer = YES |
44 |
Correct |
3 ms |
8784 KB |
answer = YES |
45 |
Correct |
2 ms |
8784 KB |
answer = YES |
46 |
Correct |
2 ms |
8784 KB |
answer = YES |
47 |
Correct |
3 ms |
8784 KB |
answer = YES |
48 |
Correct |
2 ms |
8784 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
answer = YES |
2 |
Correct |
2 ms |
8784 KB |
answer = YES |
3 |
Correct |
2 ms |
8784 KB |
answer = YES |
4 |
Correct |
2 ms |
8784 KB |
answer = NO |
5 |
Correct |
2 ms |
8784 KB |
answer = YES |
6 |
Correct |
2 ms |
8784 KB |
answer = YES |
7 |
Correct |
3 ms |
8784 KB |
answer = YES |
8 |
Correct |
2 ms |
8784 KB |
answer = YES |
9 |
Correct |
2 ms |
8784 KB |
answer = NO |
10 |
Correct |
2 ms |
8952 KB |
answer = YES |
11 |
Correct |
2 ms |
8784 KB |
answer = YES |
12 |
Correct |
2 ms |
8784 KB |
answer = NO |
13 |
Correct |
2 ms |
8784 KB |
answer = YES |
14 |
Correct |
2 ms |
8784 KB |
answer = YES |
15 |
Correct |
2 ms |
8784 KB |
answer = YES |
16 |
Correct |
2 ms |
8784 KB |
answer = YES |
17 |
Correct |
2 ms |
8848 KB |
answer = YES |
18 |
Correct |
2 ms |
8952 KB |
answer = YES |
19 |
Correct |
2 ms |
8784 KB |
answer = YES |
20 |
Correct |
2 ms |
8784 KB |
answer = YES |
21 |
Correct |
2 ms |
8784 KB |
answer = YES |
22 |
Correct |
2 ms |
8784 KB |
answer = NO |
23 |
Correct |
2 ms |
8784 KB |
answer = NO |
24 |
Correct |
2 ms |
8784 KB |
answer = YES |
25 |
Correct |
2 ms |
8784 KB |
answer = YES |
26 |
Correct |
2 ms |
8784 KB |
answer = YES |
27 |
Correct |
2 ms |
8784 KB |
answer = YES |
28 |
Correct |
2 ms |
8784 KB |
answer = YES |
29 |
Correct |
2 ms |
8952 KB |
answer = YES |
30 |
Correct |
2 ms |
8784 KB |
answer = NO |
31 |
Correct |
2 ms |
8784 KB |
answer = YES |
32 |
Correct |
2 ms |
8784 KB |
answer = YES |
33 |
Correct |
2 ms |
8784 KB |
answer = YES |
34 |
Correct |
2 ms |
8784 KB |
answer = YES |
35 |
Correct |
2 ms |
8784 KB |
answer = YES |
36 |
Correct |
2 ms |
8784 KB |
answer = YES |
37 |
Correct |
2 ms |
8784 KB |
answer = YES |
38 |
Correct |
2 ms |
8784 KB |
answer = YES |
39 |
Correct |
2 ms |
8796 KB |
answer = YES |
40 |
Correct |
2 ms |
8784 KB |
answer = YES |
41 |
Correct |
2 ms |
8808 KB |
answer = NO |
42 |
Correct |
3 ms |
8784 KB |
answer = YES |
43 |
Correct |
3 ms |
8784 KB |
answer = YES |
44 |
Correct |
3 ms |
8784 KB |
answer = YES |
45 |
Correct |
2 ms |
8784 KB |
answer = YES |
46 |
Correct |
2 ms |
8784 KB |
answer = YES |
47 |
Correct |
3 ms |
8784 KB |
answer = YES |
48 |
Correct |
2 ms |
8784 KB |
answer = YES |
49 |
Correct |
12 ms |
9564 KB |
answer = YES |
50 |
Correct |
8 ms |
9808 KB |
answer = YES |
51 |
Correct |
15 ms |
9628 KB |
answer = YES |
52 |
Correct |
10 ms |
9552 KB |
answer = NO |
53 |
Correct |
3 ms |
8784 KB |
answer = YES |
54 |
Correct |
5 ms |
8952 KB |
answer = YES |
55 |
Correct |
8 ms |
9040 KB |
answer = YES |
56 |
Correct |
12 ms |
9552 KB |
answer = YES |
57 |
Correct |
13 ms |
9296 KB |
answer = YES |
58 |
Correct |
11 ms |
9296 KB |
answer = YES |
59 |
Correct |
6 ms |
9296 KB |
answer = YES |
60 |
Correct |
12 ms |
9296 KB |
answer = YES |
61 |
Correct |
4 ms |
9208 KB |
answer = YES |
62 |
Correct |
37 ms |
15952 KB |
answer = NO |
63 |
Correct |
43 ms |
16376 KB |
answer = YES |
64 |
Correct |
40 ms |
16208 KB |
answer = NO |
65 |
Correct |
57 ms |
16296 KB |
answer = YES |
66 |
Correct |
5 ms |
8784 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
answer = YES |
2 |
Correct |
2 ms |
8784 KB |
answer = YES |
3 |
Correct |
2 ms |
8784 KB |
answer = YES |
4 |
Correct |
2 ms |
8784 KB |
answer = NO |
5 |
Correct |
2 ms |
8784 KB |
answer = YES |
6 |
Correct |
2 ms |
8784 KB |
answer = YES |
7 |
Correct |
3 ms |
8784 KB |
answer = YES |
8 |
Correct |
2 ms |
8784 KB |
answer = YES |
9 |
Correct |
2 ms |
8784 KB |
answer = NO |
10 |
Correct |
2 ms |
8952 KB |
answer = YES |
11 |
Correct |
2 ms |
8784 KB |
answer = YES |
12 |
Correct |
2 ms |
8784 KB |
answer = NO |
13 |
Correct |
2 ms |
8784 KB |
answer = YES |
14 |
Correct |
2 ms |
8784 KB |
answer = YES |
15 |
Correct |
2 ms |
8784 KB |
answer = YES |
16 |
Correct |
2 ms |
8784 KB |
answer = YES |
17 |
Correct |
2 ms |
8848 KB |
answer = YES |
18 |
Correct |
2 ms |
8952 KB |
answer = YES |
19 |
Correct |
2 ms |
8784 KB |
answer = YES |
20 |
Correct |
2 ms |
8784 KB |
answer = YES |
21 |
Correct |
2 ms |
8784 KB |
answer = YES |
22 |
Correct |
2 ms |
8784 KB |
answer = NO |
23 |
Correct |
2 ms |
8784 KB |
answer = NO |
24 |
Correct |
2 ms |
8784 KB |
answer = YES |
25 |
Correct |
2 ms |
8784 KB |
answer = YES |
26 |
Correct |
2 ms |
8784 KB |
answer = YES |
27 |
Correct |
2 ms |
8784 KB |
answer = YES |
28 |
Correct |
2 ms |
8784 KB |
answer = YES |
29 |
Correct |
2 ms |
8952 KB |
answer = YES |
30 |
Correct |
2 ms |
8784 KB |
answer = NO |
31 |
Correct |
2 ms |
8784 KB |
answer = YES |
32 |
Correct |
2 ms |
8784 KB |
answer = YES |
33 |
Correct |
2 ms |
8784 KB |
answer = YES |
34 |
Correct |
2 ms |
8784 KB |
answer = YES |
35 |
Correct |
2 ms |
8784 KB |
answer = YES |
36 |
Correct |
2 ms |
8784 KB |
answer = YES |
37 |
Correct |
2 ms |
8784 KB |
answer = YES |
38 |
Correct |
2 ms |
8784 KB |
answer = YES |
39 |
Correct |
2 ms |
8796 KB |
answer = YES |
40 |
Correct |
2 ms |
8784 KB |
answer = YES |
41 |
Correct |
2 ms |
8808 KB |
answer = NO |
42 |
Correct |
3 ms |
8784 KB |
answer = YES |
43 |
Correct |
3 ms |
8784 KB |
answer = YES |
44 |
Correct |
3 ms |
8784 KB |
answer = YES |
45 |
Correct |
2 ms |
8784 KB |
answer = YES |
46 |
Correct |
2 ms |
8784 KB |
answer = YES |
47 |
Correct |
3 ms |
8784 KB |
answer = YES |
48 |
Correct |
2 ms |
8784 KB |
answer = YES |
49 |
Correct |
12 ms |
9564 KB |
answer = YES |
50 |
Correct |
8 ms |
9808 KB |
answer = YES |
51 |
Correct |
15 ms |
9628 KB |
answer = YES |
52 |
Correct |
10 ms |
9552 KB |
answer = NO |
53 |
Correct |
3 ms |
8784 KB |
answer = YES |
54 |
Correct |
5 ms |
8952 KB |
answer = YES |
55 |
Correct |
8 ms |
9040 KB |
answer = YES |
56 |
Correct |
12 ms |
9552 KB |
answer = YES |
57 |
Correct |
13 ms |
9296 KB |
answer = YES |
58 |
Correct |
11 ms |
9296 KB |
answer = YES |
59 |
Correct |
6 ms |
9296 KB |
answer = YES |
60 |
Correct |
12 ms |
9296 KB |
answer = YES |
61 |
Correct |
4 ms |
9208 KB |
answer = YES |
62 |
Correct |
37 ms |
15952 KB |
answer = NO |
63 |
Correct |
43 ms |
16376 KB |
answer = YES |
64 |
Correct |
40 ms |
16208 KB |
answer = NO |
65 |
Correct |
57 ms |
16296 KB |
answer = YES |
66 |
Correct |
5 ms |
8784 KB |
answer = YES |
67 |
Correct |
113 ms |
23284 KB |
answer = YES |
68 |
Correct |
110 ms |
23288 KB |
answer = YES |
69 |
Correct |
56 ms |
23236 KB |
answer = YES |
70 |
Correct |
84 ms |
27584 KB |
answer = YES |
71 |
Correct |
60 ms |
23232 KB |
answer = YES |
72 |
Correct |
132 ms |
17524 KB |
answer = YES |
73 |
Correct |
59 ms |
17600 KB |
answer = YES |
74 |
Correct |
46 ms |
18116 KB |
answer = YES |
75 |
Correct |
54 ms |
17356 KB |
answer = NO |
76 |
Correct |
15 ms |
9552 KB |
answer = YES |
77 |
Correct |
38 ms |
10732 KB |
answer = YES |
78 |
Correct |
51 ms |
13772 KB |
answer = YES |
79 |
Correct |
114 ms |
16584 KB |
answer = YES |
80 |
Correct |
83 ms |
18116 KB |
answer = YES |
81 |
Correct |
31 ms |
19144 KB |
answer = NO |
82 |
Correct |
82 ms |
22984 KB |
answer = YES |
83 |
Correct |
91 ms |
23232 KB |
answer = YES |
84 |
Correct |
125 ms |
23232 KB |
answer = YES |
85 |
Correct |
117 ms |
23232 KB |
answer = YES |
86 |
Correct |
69 ms |
23232 KB |
answer = YES |
87 |
Correct |
44 ms |
17744 KB |
answer = NO |
88 |
Correct |
75 ms |
19496 KB |
answer = YES |
89 |
Correct |
59 ms |
16456 KB |
answer = YES |
90 |
Correct |
59 ms |
16468 KB |
answer = YES |
91 |
Correct |
60 ms |
16340 KB |
answer = YES |
92 |
Correct |
30 ms |
14284 KB |
answer = YES |
93 |
Correct |
29 ms |
14292 KB |
answer = YES |
94 |
Correct |
89 ms |
22208 KB |
answer = NO |
95 |
Correct |
26 ms |
15440 KB |
answer = NO |
96 |
Correct |
112 ms |
25028 KB |
answer = YES |
97 |
Correct |
78 ms |
22216 KB |
answer = NO |