# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
642689 |
2022-09-20T11:28:25 Z |
berr |
Graph (BOI20_graph) |
C++17 |
|
4 ms |
5072 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, 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=-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];
}
}
}
for(int i=1; i<=n; i++)
{
vis[i]=0;
if(!vis[i]) dfs2(i, i);
}
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 |
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 |
5072 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
3 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
4948 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
3 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4948 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4948 KB |
answer = YES |
18 |
Incorrect |
2 ms |
4948 KB |
jury has the better answer: jans = YES, pans = NO |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 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 |
5072 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
3 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
4948 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
3 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4948 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4948 KB |
answer = YES |
18 |
Incorrect |
2 ms |
4948 KB |
jury has the better answer: jans = YES, pans = NO |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 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 |
5072 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
3 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
4948 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
3 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4948 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4948 KB |
answer = YES |
18 |
Incorrect |
2 ms |
4948 KB |
jury has the better answer: jans = YES, pans = NO |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 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 |
5072 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
3 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
4948 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
3 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4948 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4948 KB |
answer = YES |
18 |
Incorrect |
2 ms |
4948 KB |
jury has the better answer: jans = YES, pans = NO |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 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 |
5072 KB |
answer = YES |
6 |
Correct |
3 ms |
4948 KB |
answer = YES |
7 |
Correct |
3 ms |
4948 KB |
answer = YES |
8 |
Correct |
2 ms |
4948 KB |
answer = YES |
9 |
Correct |
3 ms |
4948 KB |
answer = NO |
10 |
Correct |
3 ms |
4948 KB |
answer = YES |
11 |
Correct |
3 ms |
4948 KB |
answer = YES |
12 |
Correct |
3 ms |
4948 KB |
answer = NO |
13 |
Correct |
4 ms |
4948 KB |
answer = YES |
14 |
Correct |
3 ms |
4948 KB |
answer = YES |
15 |
Correct |
3 ms |
4948 KB |
answer = YES |
16 |
Correct |
3 ms |
4948 KB |
answer = YES |
17 |
Correct |
2 ms |
4948 KB |
answer = YES |
18 |
Incorrect |
2 ms |
4948 KB |
jury has the better answer: jans = YES, pans = NO |
19 |
Halted |
0 ms |
0 KB |
- |