# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
642690 |
2022-09-20T11:29:28 Z |
berr |
Graph (BOI20_graph) |
C++17 |
|
3 ms |
4992 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);
}
}
}
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, i, 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=-4e8;
for(int i=31; 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 |
2 ms |
4948 KB |
answer = YES |
2 |
Correct |
3 ms |
4948 KB |
answer = YES |
3 |
Correct |
2 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
2 ms |
4948 KB |
answer = YES |
7 |
Correct |
2 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
2 ms |
4948 KB |
answer = NO |
13 |
Correct |
3 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
2 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4912 KB |
answer = YES |
18 |
Incorrect |
3 ms |
4948 KB |
Sum of endpoints for edge (1; 1) differs from the expected value 1. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
answer = YES |
2 |
Correct |
3 ms |
4948 KB |
answer = YES |
3 |
Correct |
2 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
2 ms |
4948 KB |
answer = YES |
7 |
Correct |
2 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
2 ms |
4948 KB |
answer = NO |
13 |
Correct |
3 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
2 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4912 KB |
answer = YES |
18 |
Incorrect |
3 ms |
4948 KB |
Sum of endpoints for edge (1; 1) differs from the expected value 1. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
answer = YES |
2 |
Correct |
3 ms |
4948 KB |
answer = YES |
3 |
Correct |
2 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
2 ms |
4948 KB |
answer = YES |
7 |
Correct |
2 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
2 ms |
4948 KB |
answer = NO |
13 |
Correct |
3 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
2 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4912 KB |
answer = YES |
18 |
Incorrect |
3 ms |
4948 KB |
Sum of endpoints for edge (1; 1) differs from the expected value 1. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
answer = YES |
2 |
Correct |
3 ms |
4948 KB |
answer = YES |
3 |
Correct |
2 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
2 ms |
4948 KB |
answer = YES |
7 |
Correct |
2 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
2 ms |
4948 KB |
answer = NO |
13 |
Correct |
3 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
2 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4912 KB |
answer = YES |
18 |
Incorrect |
3 ms |
4948 KB |
Sum of endpoints for edge (1; 1) differs from the expected value 1. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
answer = YES |
2 |
Correct |
3 ms |
4948 KB |
answer = YES |
3 |
Correct |
2 ms |
4948 KB |
answer = YES |
4 |
Correct |
3 ms |
4948 KB |
answer = NO |
5 |
Correct |
3 ms |
4948 KB |
answer = YES |
6 |
Correct |
2 ms |
4948 KB |
answer = YES |
7 |
Correct |
2 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
2 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
2 ms |
4948 KB |
answer = NO |
13 |
Correct |
3 ms |
4948 KB |
answer = YES |
14 |
Correct |
2 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4992 KB |
answer = YES |
16 |
Correct |
2 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4912 KB |
answer = YES |
18 |
Incorrect |
3 ms |
4948 KB |
Sum of endpoints for edge (1; 1) differs from the expected value 1. |
19 |
Halted |
0 ms |
0 KB |
- |