# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030611 |
2024-07-22T07:35:02 Z |
ttamx |
Graph (BOI20_graph) |
C++17 |
|
132 ms |
20172 KB |
#include<bits/stdc++.h>
using namespace std;
using db = long double;
using ll = long long;
const db EPS=1e-12;
const db INVPHI=(sqrt(db(5))-1)/2;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,m;
cin >> n >> m;
vector<vector<pair<int,int>>> adj(n);
for(int i=0;i<m;i++){
int u,v,w;
cin >> u >> v >> w;
u--,v--;
adj[u].emplace_back(v,w);
adj[v].emplace_back(u,w);
}
vector<bool> vis(n);
vector<ll> a(n),b(n);
vector<int> comp;
pair<ll,ll> val;
bool found=false;
function<void(int)> dfs=[&](int u){
comp.emplace_back(u);
vis[u]=true;
for(auto [v,w]:adj[u]){
if(!vis[v]){
a[v]=-a[u];
b[v]=w-b[u];
dfs(v);
}else{
if(a[u]+a[v]==0){
if(b[u]+b[v]!=w){
cout << "NO",exit(0);
}
}else{
ll num=w-b[u]-b[v];
ll den=a[u]+a[v];
if(!found){
found=true;
val={num,den};
}else if(num*val.second!=val.first*den){
cout << "NO",exit(0);
}
}
}
}
};
vector<db> ans(n);
for(int i=0;i<n;i++)if(!vis[i]){
comp.clear();
found=false;
a[i]=1,b[i]=0;
dfs(i);
auto calc=[&](db x){
db res=0.0;
for(auto u:comp){
ans[u]=a[u]*x+b[u];
res+=abs(ans[u]);
}
return res;
};
if(found){
db x=db(val.first)/db(val.second);
calc(x);
}else{
db m=comp.size();
db l=-m,r=m;
while(r-l>EPS){
db s=(r-l)*INVPHI;
db l2=r-s,r2=l+s;
if(calc(l2)<calc(r2))r=r2;
else l=l2;
}
calc((l+r)/2.0);
}
}
cout << fixed << setprecision(10);
cout << "YES\n";
for(auto x:ans)cout << x << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
344 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
344 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
344 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
1 ms |
344 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
0 ms |
348 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
0 ms |
348 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
344 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
344 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
1 ms |
344 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
0 ms |
348 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
0 ms |
348 KB |
answer = YES |
37 |
Correct |
1 ms |
348 KB |
answer = YES |
38 |
Correct |
1 ms |
348 KB |
answer = YES |
39 |
Correct |
1 ms |
348 KB |
answer = YES |
40 |
Correct |
1 ms |
348 KB |
answer = YES |
41 |
Correct |
0 ms |
392 KB |
answer = NO |
42 |
Correct |
1 ms |
348 KB |
answer = YES |
43 |
Correct |
1 ms |
348 KB |
answer = YES |
44 |
Correct |
1 ms |
348 KB |
answer = YES |
45 |
Correct |
1 ms |
348 KB |
answer = YES |
46 |
Correct |
1 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
556 KB |
answer = YES |
48 |
Correct |
1 ms |
348 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
344 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
344 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
1 ms |
344 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
0 ms |
348 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
0 ms |
348 KB |
answer = YES |
37 |
Correct |
1 ms |
348 KB |
answer = YES |
38 |
Correct |
1 ms |
348 KB |
answer = YES |
39 |
Correct |
1 ms |
348 KB |
answer = YES |
40 |
Correct |
1 ms |
348 KB |
answer = YES |
41 |
Correct |
0 ms |
392 KB |
answer = NO |
42 |
Correct |
1 ms |
348 KB |
answer = YES |
43 |
Correct |
1 ms |
348 KB |
answer = YES |
44 |
Correct |
1 ms |
348 KB |
answer = YES |
45 |
Correct |
1 ms |
348 KB |
answer = YES |
46 |
Correct |
1 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
556 KB |
answer = YES |
48 |
Correct |
1 ms |
348 KB |
answer = YES |
49 |
Correct |
12 ms |
1628 KB |
answer = YES |
50 |
Correct |
7 ms |
1844 KB |
answer = YES |
51 |
Correct |
11 ms |
1884 KB |
answer = YES |
52 |
Correct |
2 ms |
1368 KB |
answer = NO |
53 |
Correct |
2 ms |
344 KB |
answer = YES |
54 |
Correct |
3 ms |
604 KB |
answer = YES |
55 |
Correct |
5 ms |
860 KB |
answer = YES |
56 |
Correct |
10 ms |
1368 KB |
answer = YES |
57 |
Correct |
10 ms |
1372 KB |
answer = YES |
58 |
Correct |
9 ms |
1372 KB |
answer = YES |
59 |
Correct |
5 ms |
1372 KB |
answer = YES |
60 |
Correct |
11 ms |
1572 KB |
answer = YES |
61 |
Correct |
3 ms |
860 KB |
answer = YES |
62 |
Correct |
30 ms |
5456 KB |
answer = NO |
63 |
Correct |
41 ms |
5972 KB |
answer = YES |
64 |
Correct |
33 ms |
5976 KB |
answer = NO |
65 |
Correct |
38 ms |
6036 KB |
answer = YES |
66 |
Correct |
2 ms |
600 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
344 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
344 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
1 ms |
344 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
0 ms |
348 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
0 ms |
348 KB |
answer = YES |
37 |
Correct |
1 ms |
348 KB |
answer = YES |
38 |
Correct |
1 ms |
348 KB |
answer = YES |
39 |
Correct |
1 ms |
348 KB |
answer = YES |
40 |
Correct |
1 ms |
348 KB |
answer = YES |
41 |
Correct |
0 ms |
392 KB |
answer = NO |
42 |
Correct |
1 ms |
348 KB |
answer = YES |
43 |
Correct |
1 ms |
348 KB |
answer = YES |
44 |
Correct |
1 ms |
348 KB |
answer = YES |
45 |
Correct |
1 ms |
348 KB |
answer = YES |
46 |
Correct |
1 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
556 KB |
answer = YES |
48 |
Correct |
1 ms |
348 KB |
answer = YES |
49 |
Correct |
12 ms |
1628 KB |
answer = YES |
50 |
Correct |
7 ms |
1844 KB |
answer = YES |
51 |
Correct |
11 ms |
1884 KB |
answer = YES |
52 |
Correct |
2 ms |
1368 KB |
answer = NO |
53 |
Correct |
2 ms |
344 KB |
answer = YES |
54 |
Correct |
3 ms |
604 KB |
answer = YES |
55 |
Correct |
5 ms |
860 KB |
answer = YES |
56 |
Correct |
10 ms |
1368 KB |
answer = YES |
57 |
Correct |
10 ms |
1372 KB |
answer = YES |
58 |
Correct |
9 ms |
1372 KB |
answer = YES |
59 |
Correct |
5 ms |
1372 KB |
answer = YES |
60 |
Correct |
11 ms |
1572 KB |
answer = YES |
61 |
Correct |
3 ms |
860 KB |
answer = YES |
62 |
Correct |
30 ms |
5456 KB |
answer = NO |
63 |
Correct |
41 ms |
5972 KB |
answer = YES |
64 |
Correct |
33 ms |
5976 KB |
answer = NO |
65 |
Correct |
38 ms |
6036 KB |
answer = YES |
66 |
Correct |
2 ms |
600 KB |
answer = YES |
67 |
Correct |
102 ms |
17100 KB |
answer = YES |
68 |
Correct |
99 ms |
17100 KB |
answer = YES |
69 |
Correct |
55 ms |
16976 KB |
answer = YES |
70 |
Correct |
78 ms |
20172 KB |
answer = YES |
71 |
Correct |
55 ms |
17044 KB |
answer = YES |
72 |
Correct |
132 ms |
11468 KB |
answer = YES |
73 |
Correct |
81 ms |
11392 KB |
answer = YES |
74 |
Correct |
40 ms |
10444 KB |
answer = YES |
75 |
Correct |
14 ms |
7772 KB |
answer = NO |
76 |
Correct |
13 ms |
1760 KB |
answer = YES |
77 |
Correct |
30 ms |
3164 KB |
answer = YES |
78 |
Correct |
56 ms |
5072 KB |
answer = YES |
79 |
Correct |
100 ms |
9800 KB |
answer = YES |
80 |
Correct |
86 ms |
10452 KB |
answer = YES |
81 |
Correct |
23 ms |
12752 KB |
answer = NO |
82 |
Correct |
89 ms |
16588 KB |
answer = YES |
83 |
Correct |
75 ms |
17100 KB |
answer = YES |
84 |
Correct |
128 ms |
17128 KB |
answer = YES |
85 |
Correct |
91 ms |
17096 KB |
answer = YES |
86 |
Correct |
54 ms |
17100 KB |
answer = YES |
87 |
Correct |
22 ms |
11076 KB |
answer = NO |
88 |
Correct |
89 ms |
13328 KB |
answer = YES |
89 |
Correct |
54 ms |
10324 KB |
answer = YES |
90 |
Correct |
54 ms |
10320 KB |
answer = YES |
91 |
Correct |
53 ms |
10260 KB |
answer = YES |
92 |
Correct |
34 ms |
6104 KB |
answer = YES |
93 |
Correct |
25 ms |
5824 KB |
answer = YES |
94 |
Correct |
27 ms |
15816 KB |
answer = NO |
95 |
Correct |
23 ms |
9052 KB |
answer = NO |
96 |
Correct |
88 ms |
17504 KB |
answer = YES |
97 |
Correct |
22 ms |
15816 KB |
answer = NO |