#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n, m, u, v, w, a[nx], b[nx], f, vs[nx];
double res[nx];
vector<pair<int, int>> d[nx];
vector<int> comp;
set<double> s;
void dfs(int u, int p)
{
vs[u]=1;
comp.push_back(u);
for (auto [v, w]:d[u])
{
if (v==p) continue;
if (vs[v])
{
int sma=a[u]+a[v], smb=b[u]+b[v];
if (a[u]+a[v]==0&&b[u]+b[v]==w) continue;
smb=w-smb;
s.insert(((double)smb)/((double)sma));
}
else
{
a[v]=-a[u];
b[v]=w-b[u];
dfs(v, u);
}
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w});
for (int i=1; i<=n; i++)
{
if (!vs[i])
{
comp.clear();
s.clear();
a[i]=1;
dfs(i, i);
if (s.size()>1) f=1;
else if (s.size()==1)
{
double vl=*s.begin();
for (auto x:comp) res[x]=a[x]*vl+b[x];
}
else
{
for (auto x:comp) res[x]=b[x];
}
}
}
if (f) return cout<<"NO\n", 0;
cout<<"YES\n";
for (int i=1; i<=n; i++) cout<<setprecision(8)<<res[i]<<' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2908 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2908 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2908 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2908 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2908 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |