# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
642770 |
2022-09-20T13:18:33 Z |
berr |
Graph (BOI20_graph) |
C++17 |
|
165 ms |
28980 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int c[(int)1e5+5], val[(int)1e5+5], vis[(int)(1e5+5)], val2[(int)(1e5)+5];
vector<array<int, 2>> adj[(int)(1e5+5)];
vector<int> pos[(int)(1e5+5)], aaa;
int flag=1;
void dfs(int x, int y, int z)
{
vis[x]=z;
pos[z].push_back(x);
for(auto i: adj[x])
{
if(i[0]==y) continue;
if(vis[i[0]]!=0)
{
if(c[x]+c[i[0]]==0&&val[i[0]]+val[x]!=i[1])
{
flag=0;
}
else if(c[x]+c[i[0]]!=0)
{
if(val2[z]==-1)
{
val2[z]=(i[1]-val[i[0]]-val[x])/(c[x]+c[i[0]]);
}
else
{
if(val2[z]!=(i[1]-val[i[0]]-val[x])/(c[x]+c[i[0]])) flag=0;
}
}
}
else
{
val[i[0]]=i[1]-val[x];
c[i[0]]=-1*c[x];
dfs(i[0], x, z);
}
}
}
void dfs2(int z, int p)
{
vis[z]=1;
for(auto i: adj[z])
{
if(val[i[0]]+val[z]!=i[1]) flag=0;
else if(!vis[i[0]]) dfs2(i[0], z);
}
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin>>n>>m;
for(int i=0; i<m; i++)
{
int x, y, z; cin>>x>>y>>z;
z*=1e7;
adj[x].push_back({y, z});
adj[y].push_back({x, z});
}
for(int i=1; i<=n; i++)
{
val2[i]=-1;
}
for(int i=1; i<=n; i++)
{
if(!vis[i]) c[i]=1,dfs(i, 0, i), aaa.push_back(i);
}
for(auto z: aaa)
{
if(val2[z]!=-1)
{
for(auto i: pos[z])
{
val[i]+=c[i]*val2[z];
}
}
else
{
int s=-1e10;
for(int i=40; i>=0; i--)
{
int tmp=s+(1LL<<i);
int ans1=0, ans2=0;
int tmp2=tmp-1;
for(auto j: pos[z])
{
ans1+=abs(val[j]+(c[j]*tmp));
ans2+=abs(val[j]+(c[j]*tmp2));
}
if(ans1<ans2) s=tmp;
}
val2[z]=s;
for(auto i: pos[z])
{
val[i]+=c[i]*val2[z];
}
}
}
if(flag)
{
cout<<"YES\n";
for(int i=1; i<=n; i++)
{
float x=(float)val[i]/(float)10000000;
cout<<fixed<<x<<" ";
}
}
else
{
cout<<"NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
answer = YES |
2 |
Correct |
2 ms |
4948 KB |
answer = YES |
3 |
Correct |
3 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
5028 KB |
answer = YES |
8 |
Correct |
3 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
5024 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
5076 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
2 ms |
5024 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
3 ms |
4948 KB |
answer = YES |
18 |
Correct |
3 ms |
5024 KB |
answer = YES |
19 |
Correct |
3 ms |
4948 KB |
answer = YES |
20 |
Correct |
3 ms |
4948 KB |
answer = YES |
21 |
Correct |
2 ms |
4948 KB |
answer = YES |
22 |
Correct |
3 ms |
4948 KB |
answer = NO |
23 |
Correct |
3 ms |
4948 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
answer = YES |
2 |
Correct |
2 ms |
4948 KB |
answer = YES |
3 |
Correct |
3 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
5028 KB |
answer = YES |
8 |
Correct |
3 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
5024 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
5076 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
2 ms |
5024 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
3 ms |
4948 KB |
answer = YES |
18 |
Correct |
3 ms |
5024 KB |
answer = YES |
19 |
Correct |
3 ms |
4948 KB |
answer = YES |
20 |
Correct |
3 ms |
4948 KB |
answer = YES |
21 |
Correct |
2 ms |
4948 KB |
answer = YES |
22 |
Correct |
3 ms |
4948 KB |
answer = NO |
23 |
Correct |
3 ms |
4948 KB |
answer = NO |
24 |
Correct |
3 ms |
4948 KB |
answer = YES |
25 |
Correct |
3 ms |
4948 KB |
answer = YES |
26 |
Correct |
4 ms |
5028 KB |
answer = YES |
27 |
Correct |
3 ms |
5028 KB |
answer = YES |
28 |
Correct |
3 ms |
5028 KB |
answer = YES |
29 |
Correct |
3 ms |
5024 KB |
answer = YES |
30 |
Correct |
3 ms |
4948 KB |
answer = NO |
31 |
Correct |
3 ms |
5032 KB |
answer = YES |
32 |
Correct |
3 ms |
4948 KB |
answer = YES |
33 |
Correct |
3 ms |
4996 KB |
answer = YES |
34 |
Correct |
3 ms |
4948 KB |
answer = YES |
35 |
Correct |
3 ms |
4948 KB |
answer = YES |
36 |
Correct |
3 ms |
4948 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
answer = YES |
2 |
Correct |
2 ms |
4948 KB |
answer = YES |
3 |
Correct |
3 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
5028 KB |
answer = YES |
8 |
Correct |
3 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
5024 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
5076 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
2 ms |
5024 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
3 ms |
4948 KB |
answer = YES |
18 |
Correct |
3 ms |
5024 KB |
answer = YES |
19 |
Correct |
3 ms |
4948 KB |
answer = YES |
20 |
Correct |
3 ms |
4948 KB |
answer = YES |
21 |
Correct |
2 ms |
4948 KB |
answer = YES |
22 |
Correct |
3 ms |
4948 KB |
answer = NO |
23 |
Correct |
3 ms |
4948 KB |
answer = NO |
24 |
Correct |
3 ms |
4948 KB |
answer = YES |
25 |
Correct |
3 ms |
4948 KB |
answer = YES |
26 |
Correct |
4 ms |
5028 KB |
answer = YES |
27 |
Correct |
3 ms |
5028 KB |
answer = YES |
28 |
Correct |
3 ms |
5028 KB |
answer = YES |
29 |
Correct |
3 ms |
5024 KB |
answer = YES |
30 |
Correct |
3 ms |
4948 KB |
answer = NO |
31 |
Correct |
3 ms |
5032 KB |
answer = YES |
32 |
Correct |
3 ms |
4948 KB |
answer = YES |
33 |
Correct |
3 ms |
4996 KB |
answer = YES |
34 |
Correct |
3 ms |
4948 KB |
answer = YES |
35 |
Correct |
3 ms |
4948 KB |
answer = YES |
36 |
Correct |
3 ms |
4948 KB |
answer = YES |
37 |
Correct |
3 ms |
5032 KB |
answer = YES |
38 |
Correct |
4 ms |
4948 KB |
answer = YES |
39 |
Correct |
3 ms |
5076 KB |
answer = YES |
40 |
Correct |
3 ms |
5164 KB |
answer = YES |
41 |
Correct |
3 ms |
5068 KB |
answer = NO |
42 |
Correct |
4 ms |
5164 KB |
answer = YES |
43 |
Correct |
5 ms |
5076 KB |
answer = YES |
44 |
Correct |
4 ms |
5076 KB |
answer = YES |
45 |
Correct |
4 ms |
5076 KB |
answer = YES |
46 |
Correct |
3 ms |
5076 KB |
answer = YES |
47 |
Correct |
3 ms |
5076 KB |
answer = YES |
48 |
Correct |
3 ms |
5076 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
answer = YES |
2 |
Correct |
2 ms |
4948 KB |
answer = YES |
3 |
Correct |
3 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
5028 KB |
answer = YES |
8 |
Correct |
3 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
5024 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
5076 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
2 ms |
5024 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
3 ms |
4948 KB |
answer = YES |
18 |
Correct |
3 ms |
5024 KB |
answer = YES |
19 |
Correct |
3 ms |
4948 KB |
answer = YES |
20 |
Correct |
3 ms |
4948 KB |
answer = YES |
21 |
Correct |
2 ms |
4948 KB |
answer = YES |
22 |
Correct |
3 ms |
4948 KB |
answer = NO |
23 |
Correct |
3 ms |
4948 KB |
answer = NO |
24 |
Correct |
3 ms |
4948 KB |
answer = YES |
25 |
Correct |
3 ms |
4948 KB |
answer = YES |
26 |
Correct |
4 ms |
5028 KB |
answer = YES |
27 |
Correct |
3 ms |
5028 KB |
answer = YES |
28 |
Correct |
3 ms |
5028 KB |
answer = YES |
29 |
Correct |
3 ms |
5024 KB |
answer = YES |
30 |
Correct |
3 ms |
4948 KB |
answer = NO |
31 |
Correct |
3 ms |
5032 KB |
answer = YES |
32 |
Correct |
3 ms |
4948 KB |
answer = YES |
33 |
Correct |
3 ms |
4996 KB |
answer = YES |
34 |
Correct |
3 ms |
4948 KB |
answer = YES |
35 |
Correct |
3 ms |
4948 KB |
answer = YES |
36 |
Correct |
3 ms |
4948 KB |
answer = YES |
37 |
Correct |
3 ms |
5032 KB |
answer = YES |
38 |
Correct |
4 ms |
4948 KB |
answer = YES |
39 |
Correct |
3 ms |
5076 KB |
answer = YES |
40 |
Correct |
3 ms |
5164 KB |
answer = YES |
41 |
Correct |
3 ms |
5068 KB |
answer = NO |
42 |
Correct |
4 ms |
5164 KB |
answer = YES |
43 |
Correct |
5 ms |
5076 KB |
answer = YES |
44 |
Correct |
4 ms |
5076 KB |
answer = YES |
45 |
Correct |
4 ms |
5076 KB |
answer = YES |
46 |
Correct |
3 ms |
5076 KB |
answer = YES |
47 |
Correct |
3 ms |
5076 KB |
answer = YES |
48 |
Correct |
3 ms |
5076 KB |
answer = YES |
49 |
Correct |
12 ms |
6228 KB |
answer = YES |
50 |
Correct |
12 ms |
6700 KB |
answer = YES |
51 |
Correct |
14 ms |
6636 KB |
answer = YES |
52 |
Correct |
8 ms |
6484 KB |
answer = NO |
53 |
Correct |
5 ms |
5076 KB |
answer = YES |
54 |
Correct |
6 ms |
5220 KB |
answer = YES |
55 |
Correct |
7 ms |
5676 KB |
answer = YES |
56 |
Correct |
11 ms |
6228 KB |
answer = YES |
57 |
Correct |
11 ms |
6132 KB |
answer = YES |
58 |
Correct |
10 ms |
6100 KB |
answer = YES |
59 |
Correct |
9 ms |
6100 KB |
answer = YES |
60 |
Correct |
11 ms |
6192 KB |
answer = YES |
61 |
Correct |
8 ms |
5588 KB |
answer = YES |
62 |
Correct |
61 ms |
15384 KB |
answer = NO |
63 |
Correct |
69 ms |
15444 KB |
answer = YES |
64 |
Correct |
58 ms |
15368 KB |
answer = NO |
65 |
Correct |
67 ms |
15564 KB |
answer = YES |
66 |
Correct |
5 ms |
5204 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
answer = YES |
2 |
Correct |
2 ms |
4948 KB |
answer = YES |
3 |
Correct |
3 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
5028 KB |
answer = YES |
8 |
Correct |
3 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
5024 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
5076 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
2 ms |
5024 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
3 ms |
4948 KB |
answer = YES |
18 |
Correct |
3 ms |
5024 KB |
answer = YES |
19 |
Correct |
3 ms |
4948 KB |
answer = YES |
20 |
Correct |
3 ms |
4948 KB |
answer = YES |
21 |
Correct |
2 ms |
4948 KB |
answer = YES |
22 |
Correct |
3 ms |
4948 KB |
answer = NO |
23 |
Correct |
3 ms |
4948 KB |
answer = NO |
24 |
Correct |
3 ms |
4948 KB |
answer = YES |
25 |
Correct |
3 ms |
4948 KB |
answer = YES |
26 |
Correct |
4 ms |
5028 KB |
answer = YES |
27 |
Correct |
3 ms |
5028 KB |
answer = YES |
28 |
Correct |
3 ms |
5028 KB |
answer = YES |
29 |
Correct |
3 ms |
5024 KB |
answer = YES |
30 |
Correct |
3 ms |
4948 KB |
answer = NO |
31 |
Correct |
3 ms |
5032 KB |
answer = YES |
32 |
Correct |
3 ms |
4948 KB |
answer = YES |
33 |
Correct |
3 ms |
4996 KB |
answer = YES |
34 |
Correct |
3 ms |
4948 KB |
answer = YES |
35 |
Correct |
3 ms |
4948 KB |
answer = YES |
36 |
Correct |
3 ms |
4948 KB |
answer = YES |
37 |
Correct |
3 ms |
5032 KB |
answer = YES |
38 |
Correct |
4 ms |
4948 KB |
answer = YES |
39 |
Correct |
3 ms |
5076 KB |
answer = YES |
40 |
Correct |
3 ms |
5164 KB |
answer = YES |
41 |
Correct |
3 ms |
5068 KB |
answer = NO |
42 |
Correct |
4 ms |
5164 KB |
answer = YES |
43 |
Correct |
5 ms |
5076 KB |
answer = YES |
44 |
Correct |
4 ms |
5076 KB |
answer = YES |
45 |
Correct |
4 ms |
5076 KB |
answer = YES |
46 |
Correct |
3 ms |
5076 KB |
answer = YES |
47 |
Correct |
3 ms |
5076 KB |
answer = YES |
48 |
Correct |
3 ms |
5076 KB |
answer = YES |
49 |
Correct |
12 ms |
6228 KB |
answer = YES |
50 |
Correct |
12 ms |
6700 KB |
answer = YES |
51 |
Correct |
14 ms |
6636 KB |
answer = YES |
52 |
Correct |
8 ms |
6484 KB |
answer = NO |
53 |
Correct |
5 ms |
5076 KB |
answer = YES |
54 |
Correct |
6 ms |
5220 KB |
answer = YES |
55 |
Correct |
7 ms |
5676 KB |
answer = YES |
56 |
Correct |
11 ms |
6228 KB |
answer = YES |
57 |
Correct |
11 ms |
6132 KB |
answer = YES |
58 |
Correct |
10 ms |
6100 KB |
answer = YES |
59 |
Correct |
9 ms |
6100 KB |
answer = YES |
60 |
Correct |
11 ms |
6192 KB |
answer = YES |
61 |
Correct |
8 ms |
5588 KB |
answer = YES |
62 |
Correct |
61 ms |
15384 KB |
answer = NO |
63 |
Correct |
69 ms |
15444 KB |
answer = YES |
64 |
Correct |
58 ms |
15368 KB |
answer = NO |
65 |
Correct |
67 ms |
15564 KB |
answer = YES |
66 |
Correct |
5 ms |
5204 KB |
answer = YES |
67 |
Correct |
96 ms |
22800 KB |
answer = YES |
68 |
Correct |
82 ms |
22744 KB |
answer = YES |
69 |
Correct |
79 ms |
22716 KB |
answer = YES |
70 |
Correct |
116 ms |
28980 KB |
answer = YES |
71 |
Correct |
78 ms |
22720 KB |
answer = YES |
72 |
Correct |
111 ms |
15448 KB |
answer = YES |
73 |
Correct |
101 ms |
15372 KB |
answer = YES |
74 |
Correct |
65 ms |
15708 KB |
answer = YES |
75 |
Correct |
45 ms |
14964 KB |
answer = NO |
76 |
Correct |
13 ms |
6448 KB |
answer = YES |
77 |
Correct |
26 ms |
7780 KB |
answer = YES |
78 |
Correct |
48 ms |
9596 KB |
answer = YES |
79 |
Correct |
92 ms |
13908 KB |
answer = YES |
80 |
Correct |
73 ms |
15844 KB |
answer = YES |
81 |
Correct |
48 ms |
17980 KB |
answer = NO |
82 |
Correct |
109 ms |
22076 KB |
answer = YES |
83 |
Correct |
121 ms |
23480 KB |
answer = YES |
84 |
Correct |
136 ms |
23300 KB |
answer = YES |
85 |
Correct |
92 ms |
22796 KB |
answer = YES |
86 |
Correct |
82 ms |
22872 KB |
answer = YES |
87 |
Correct |
71 ms |
17332 KB |
answer = NO |
88 |
Correct |
119 ms |
18748 KB |
answer = YES |
89 |
Correct |
97 ms |
15736 KB |
answer = YES |
90 |
Correct |
98 ms |
16756 KB |
answer = YES |
91 |
Correct |
117 ms |
17268 KB |
answer = YES |
92 |
Correct |
42 ms |
10764 KB |
answer = YES |
93 |
Correct |
41 ms |
10788 KB |
answer = YES |
94 |
Correct |
78 ms |
23392 KB |
answer = NO |
95 |
Correct |
59 ms |
16428 KB |
answer = NO |
96 |
Correct |
165 ms |
27696 KB |
answer = YES |
97 |
Correct |
46 ms |
22820 KB |
answer = NO |