# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
779754 |
2023-07-11T18:40:48 Z |
FEDIKUS |
Graph (BOI20_graph) |
C++17 |
|
2 ms |
2652 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll maxn=1e5+10;
vector<pair<ll,ll> > g[maxn];
bool moze=true;
bool vis[maxn];
ll val[maxn];
ll sgn[maxn];
set<ll> a;
void dfs(ll node){
vis[node]=true;
for(auto i:g[node]){
if(vis[i.first]){
if(sgn[i.first]!=sgn[node] && val[i.first]+val[node]!=i.second) moze=false;
if(sgn[i.first]==sgn[node]){
if(sgn[i.first]==1) a.emplace(i.second-val[node]-val[i.first]);
else a.emplace(val[i.first]+val[node]-i.second);
}
}else{
sgn[i.first]=-sgn[node];
val[i.first]=i.second-val[node];
dfs(i.first);
}
}
}
int main(){
ll n,m;
cin>>n>>m;
for(ll i=0;i<m;i++){
ll u,v,c;
cin>>u>>v>>c;
g[u].push_back({v,c});
g[v].push_back({u,c});
}
sgn[1]=1;
val[1]=0;
dfs(1);
if(!moze || a.size()>1){
cout<<"NO\n";
return 0;
}else cout<<"YES\n";
if(a.size()==1){
cout<<fixed<<showpoint<<setprecision(10);
double aa=double(*a.begin())/2;
for(ll i=1;i<=n;i++){
cout<<aa*sgn[i]+val[i]<<" ";
}
return 0;
}
ll best=0;
ll curr=LLONG_MAX;
for(ll i=1;i<=n;i++){
ll sum=0;
for(ll j=1;j<=n;j++){
sum+=abs(val[j]+val[i]*sgn[j]);
}
if(sum<curr){
curr=sum;
best=val[i];
}
}
for(ll i=1;i<=n;i++){
ll sum=0;
for(ll j=1;j<=n;j++){
sum+=abs(val[j]-val[i]*sgn[j]);
}
if(sum<curr){
curr=sum;
best=-val[i];
}
}
for(ll i=1;i<=n;i++){
cout<<val[i]+best*sgn[i]<<" ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Incorrect |
1 ms |
2644 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Incorrect |
1 ms |
2644 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Incorrect |
1 ms |
2644 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Incorrect |
1 ms |
2644 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Incorrect |
1 ms |
2644 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |