# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
650537 |
2022-10-14T08:02:13 Z |
DJeniUp |
Graph (BOI20_graph) |
C++17 |
|
158 ms |
21180 KB |
#include "bits/stdc++.h"
//#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
#define INF 100000000007
#define endl '\n'
#define MOD 998244353
#define A 31
#define N 100007
#define eps 0.0000000001
ll n,m,a[N],b[N],f[N];
ld res[N];
vector<pairll>v[N];
vector<ll>num;
ld S(ll x,ll a1,ll b1,ll y){
if(f[x]==1 && a[x]!=a1){
return ld(b1-b[x])/ld(a[x]-a1);
}else if(f[x]==1 && b[x]!=b1)return -INF;
else if(f[x]==1)return INF;
num.pb(x);
f[x]=1;
a[x]=a1;
b[x]=b1;
for(int i=0;i<v[x].size();i++){
if(v[x][i].fr!=y){
ld r=S(v[x][i].fr,0-a1,v[x][i].sc-b1,x);
if(r!=INF)return r;
}
}
return INF;
}
ll D(ll x,ll y,ld a1){
f[x]=2;
res[x]=a1;
for(auto it:v[x]){
if(it.fr!=y){
if(f[it.fr]==2){
if(abs(a1+res[it.fr]-ld(it.sc))>eps)return 1;
}else{
ll r=D(it.fr,x,ld(it.sc)-a1);
if(r==1)return 1;
}
}
}
return 0;
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
ll x,y,z;
cin>>x>>y>>z;
v[x].pb({y,z});
v[y].pb({x,z});
}
for(int i=1;i<=n;i++){
if(f[i]==0){
num.clear();
ld x=S(i,1,0,0);
if(x==-INF){
cout<<"NO"<<endl;
return 0;
}else if(x==INF){
ld l=-100;
ld r=100;
ld r1=0;
ld r2=0;
while(r-l>eps){
ld m1=(l+(r-l)/3.0);
ld m2=(r-(r-l)/3.0);
r1=0;
r2=0;
for(auto j:num){
r1+=abs(m1*ld(a[j])+ld(b[j]));
r2+=abs(m2*ld(a[j])+ld(b[j]));
}
if(r1<r2)r=m2;
else l=m1;
}
for(auto j:num){
res[j]=l*ld(a[j])+ld(b[j]);
}
}else{
ll r=D(i,0,x);
if(r==1){
cout<<"NO"<<endl;
return 0;
}
}
}
}
cout<<"YES"<<endl;
for(int i=1;i<=n;i++){
cout<<fixed<<setprecision(10)<<res[i]<<" ";
}
cout<<endl;
return 0;
}
Compilation message
Graph.cpp: In function 'ld S(ll, ll, ll, ll)':
Graph.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
3 ms |
2644 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
3 ms |
2772 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Correct |
3 ms |
2772 KB |
answer = YES |
45 |
Correct |
3 ms |
2772 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2796 KB |
answer = YES |
48 |
Correct |
3 ms |
2772 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
3 ms |
2644 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
3 ms |
2772 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Correct |
3 ms |
2772 KB |
answer = YES |
45 |
Correct |
3 ms |
2772 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2796 KB |
answer = YES |
48 |
Correct |
3 ms |
2772 KB |
answer = YES |
49 |
Correct |
16 ms |
3924 KB |
answer = YES |
50 |
Correct |
15 ms |
4336 KB |
answer = YES |
51 |
Correct |
19 ms |
4252 KB |
answer = YES |
52 |
Correct |
11 ms |
3468 KB |
answer = NO |
53 |
Correct |
3 ms |
2772 KB |
answer = YES |
54 |
Correct |
6 ms |
2912 KB |
answer = YES |
55 |
Correct |
9 ms |
3284 KB |
answer = YES |
56 |
Correct |
16 ms |
3952 KB |
answer = YES |
57 |
Correct |
17 ms |
3824 KB |
answer = YES |
58 |
Correct |
15 ms |
3796 KB |
answer = YES |
59 |
Correct |
13 ms |
3692 KB |
answer = YES |
60 |
Correct |
16 ms |
3936 KB |
answer = YES |
61 |
Correct |
8 ms |
3284 KB |
answer = YES |
62 |
Correct |
143 ms |
14372 KB |
answer = NO |
63 |
Correct |
141 ms |
15068 KB |
answer = YES |
64 |
Correct |
145 ms |
14900 KB |
answer = NO |
65 |
Correct |
145 ms |
14968 KB |
answer = YES |
66 |
Correct |
4 ms |
2900 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2644 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
3 ms |
2644 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
3 ms |
2772 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Correct |
3 ms |
2772 KB |
answer = YES |
45 |
Correct |
3 ms |
2772 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2796 KB |
answer = YES |
48 |
Correct |
3 ms |
2772 KB |
answer = YES |
49 |
Correct |
16 ms |
3924 KB |
answer = YES |
50 |
Correct |
15 ms |
4336 KB |
answer = YES |
51 |
Correct |
19 ms |
4252 KB |
answer = YES |
52 |
Correct |
11 ms |
3468 KB |
answer = NO |
53 |
Correct |
3 ms |
2772 KB |
answer = YES |
54 |
Correct |
6 ms |
2912 KB |
answer = YES |
55 |
Correct |
9 ms |
3284 KB |
answer = YES |
56 |
Correct |
16 ms |
3952 KB |
answer = YES |
57 |
Correct |
17 ms |
3824 KB |
answer = YES |
58 |
Correct |
15 ms |
3796 KB |
answer = YES |
59 |
Correct |
13 ms |
3692 KB |
answer = YES |
60 |
Correct |
16 ms |
3936 KB |
answer = YES |
61 |
Correct |
8 ms |
3284 KB |
answer = YES |
62 |
Correct |
143 ms |
14372 KB |
answer = NO |
63 |
Correct |
141 ms |
15068 KB |
answer = YES |
64 |
Correct |
145 ms |
14900 KB |
answer = NO |
65 |
Correct |
145 ms |
14968 KB |
answer = YES |
66 |
Correct |
4 ms |
2900 KB |
answer = YES |
67 |
Incorrect |
158 ms |
21180 KB |
participant answer is too inprecise |
68 |
Halted |
0 ms |
0 KB |
- |