///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define N 100001
int e;
bool V[N];
double val[N];
map<int,bool> vis;
vector<pair<int,double>> a[N];
vector<double> x{-2,-1.5,-1,-0.5,0,0.5,1,1.5,2};
double dfs(int v){
V[v]=1;
vis[v]=1;
double o=abs(val[v]);
for(auto& i:a[v]){
if(!e) return 0;
if(vis[i.ff]){
if(val[i.ff]+val[v]!=i.ss)
e=0;
}
else{
val[i.ff]=i.ss-val[v];
o+=dfs(i.ff);
}
}
return o;
}
void set_val(int v){
vis[v]=1;
for(auto& i:a[v]){
if(vis[i.ff]) continue;
val[i.ff]=i.ss-val[v];
set_val(i.ff);
}
}
void solve(){
double r;
int n,m,p,q;
pair<double,double> s;
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>p>>q>>r;
a[p].append({q,r});
a[q].append({p,r});
}
for(int i=1;i<=n;i++){
if(V[i]) continue;
s={1e9,1e9};
for(auto& j:x){
vis.clear();
val[i]=j;
r=dfs(i);
if(e) s=min(s,{r,j});
e=1;
}
if(s.ff==1e9){
cout<<"NO";
return;
}
val[i]=s.ss;
vis.clear();
set_val(i);
}
cout<<"YES\n";
for(int i=1;i<=n;i++)
cout<<val[i]<<' ';
}
int main(){
L0TA;
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2804 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
2 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2648 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
2 ms |
2656 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2652 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2648 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2804 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
2 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2648 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
2 ms |
2656 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2652 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2648 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2804 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
2 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2648 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
2 ms |
2656 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2652 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2648 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2804 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
2 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2648 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
2 ms |
2656 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2652 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2648 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2804 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
2 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2648 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
2 ms |
2656 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2652 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2652 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2648 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Incorrect |
1 ms |
2652 KB |
participant answer is larger than the answer of jury |
27 |
Halted |
0 ms |
0 KB |
- |