#include<iostream>
#include<random>
#include<ctime>
#include<vector>
#include<bitset>
#include<iomanip>
#include<algorithm>
#pragma GCC optimize("Ofast","fast-math")
using namespace std;
using pii = pair<int,int>;
using pid = pair<int,double>;
const double bulan[] = {0,0.5,-0.5,-1,1,-1.5,1.5,-2,2,2.5,-2.5,3,-3,3.5,-3.5,4,-4,4.5,-4.5,
5,-5,5.5,-5.5,6,6.5,-6,-6.5};
constexpr double eps = 1e-6;
constexpr int NMAX = 1e5 + 1;
mt19937 rng(time(nullptr));
bitset<NMAX> viz,fix; double ans[NMAX];
vector<pii> vecini[NMAX];
void dfs(int a,vector<int> &u)
{
u.emplace_back(a); viz[a] = 1;
for(auto &it : vecini[a])
if(!viz[it.first]) dfs(it.first,u);
}
void go(int a,double v,vector<pid> &res)
{
res.push_back({a,v}); viz[a] = 1; ans[a] = v;
for(auto &it : vecini[a])
{
if(!viz[it.first])
go(it.first,it.second - v,res);
}
}
long double ab(vector<pid> &h)
{
long double res = 0;
for(auto &it : h) res += abs(it.second);
return res;
}
bool ok(vector<int> &h)
{
for(auto &f : h)
{
for(auto &s : vecini[f])
{
if(abs(ans[f] + ans[s.first] - s.second) > eps)
return 0;
}
}
return 1;
}
void solve(vector<int> &comp)
{
for(auto &v : comp)
{
if(fix[v])
{
vector<pid> h; go(v,ans[v],h);
for(auto &it : h) ans[it.first] = it.second;
return;
}
}
long double mini = 1e18; vector<pid> res;
uniform_int_distribution<int> d(0,comp.size()-1);
for(int ty = 0; ty < 3; ty++)
{
int mumu = comp[d(rng)];
for(auto &val : bulan)
{
for(auto &it : comp) viz[it] = 0;
vector<pid> h; go(mumu,val,h); double now = ab(h);
if(now < mini && ok(comp))
{
mini = now;
res.swap(h);
}
}
}
for(auto &it : res)
ans[it.first] = it.second;
}
int main()
{
int n,m,a,b,c; cin >> n >> m;
for(int i = 1; i <= m ; i++)
{
cin >> a >> b >> c;
vecini[a].push_back({b,c});
vecini[b].push_back({a,c});
if(a == b)
{
fix[a] = 1;
ans[a] = (1.0 * c / 2);
}
}
vector<vector<int>> comps;
for(int i = 1; i <= n ; i++)
{
if(!viz[i])
{
vector<int> comp;
dfs(i,comp); comps.push_back(comp);
}
}
viz.reset();
for(auto &it : comps)
solve(it);
bool okk = 1;
for(auto &c : comps) okk &= ok(c);
if(!okk) cout << "NO";
else
{
cout << "YES\n";
for(int i = 1; i <= n ; i++)
cout << fixed << setprecision(2) << ans[i] << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2648 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2648 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2768 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
2 ms |
2876 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2648 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
2 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2648 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2648 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2768 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
2 ms |
2876 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2648 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
2 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 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 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
2 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2648 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2648 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2648 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2648 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2768 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
2 ms |
2876 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2648 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
2 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 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 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
2 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2648 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2648 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
37 |
Correct |
2 ms |
2648 KB |
answer = YES |
38 |
Correct |
3 ms |
2652 KB |
answer = YES |
39 |
Correct |
3 ms |
2652 KB |
answer = YES |
40 |
Correct |
4 ms |
2908 KB |
answer = YES |
41 |
Correct |
3 ms |
2908 KB |
answer = NO |
42 |
Correct |
4 ms |
2908 KB |
answer = YES |
43 |
Correct |
4 ms |
2660 KB |
answer = YES |
44 |
Correct |
4 ms |
2652 KB |
answer = YES |
45 |
Correct |
2 ms |
2652 KB |
answer = YES |
46 |
Correct |
2 ms |
2648 KB |
answer = YES |
47 |
Correct |
2 ms |
2652 KB |
answer = YES |
48 |
Correct |
2 ms |
2908 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2648 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2648 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2768 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
2 ms |
2876 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2648 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
2 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 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 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
2 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2648 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2648 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
37 |
Correct |
2 ms |
2648 KB |
answer = YES |
38 |
Correct |
3 ms |
2652 KB |
answer = YES |
39 |
Correct |
3 ms |
2652 KB |
answer = YES |
40 |
Correct |
4 ms |
2908 KB |
answer = YES |
41 |
Correct |
3 ms |
2908 KB |
answer = NO |
42 |
Correct |
4 ms |
2908 KB |
answer = YES |
43 |
Correct |
4 ms |
2660 KB |
answer = YES |
44 |
Correct |
4 ms |
2652 KB |
answer = YES |
45 |
Correct |
2 ms |
2652 KB |
answer = YES |
46 |
Correct |
2 ms |
2648 KB |
answer = YES |
47 |
Correct |
2 ms |
2652 KB |
answer = YES |
48 |
Correct |
2 ms |
2908 KB |
answer = YES |
49 |
Correct |
44 ms |
3876 KB |
answer = YES |
50 |
Correct |
38 ms |
4140 KB |
answer = YES |
51 |
Correct |
34 ms |
4320 KB |
answer = YES |
52 |
Correct |
36 ms |
4284 KB |
answer = NO |
53 |
Correct |
4 ms |
2904 KB |
answer = YES |
54 |
Correct |
8 ms |
2908 KB |
answer = YES |
55 |
Correct |
19 ms |
3356 KB |
answer = YES |
56 |
Correct |
35 ms |
3800 KB |
answer = YES |
57 |
Correct |
30 ms |
3420 KB |
answer = YES |
58 |
Correct |
28 ms |
3548 KB |
answer = YES |
59 |
Correct |
10 ms |
3420 KB |
answer = YES |
60 |
Correct |
33 ms |
3628 KB |
answer = YES |
61 |
Correct |
6 ms |
3420 KB |
answer = YES |
62 |
Correct |
99 ms |
8424 KB |
answer = NO |
63 |
Correct |
104 ms |
8308 KB |
answer = YES |
64 |
Correct |
111 ms |
8272 KB |
answer = NO |
65 |
Correct |
109 ms |
8452 KB |
answer = YES |
66 |
Correct |
6 ms |
2908 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
answer = YES |
2 |
Correct |
1 ms |
2648 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2652 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2648 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2648 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2768 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2652 KB |
answer = NO |
13 |
Correct |
2 ms |
2876 KB |
answer = YES |
14 |
Correct |
1 ms |
2652 KB |
answer = YES |
15 |
Correct |
1 ms |
2648 KB |
answer = YES |
16 |
Correct |
1 ms |
2652 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
1 ms |
2652 KB |
answer = YES |
20 |
Correct |
2 ms |
2652 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 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 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
2 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2652 KB |
answer = YES |
30 |
Correct |
1 ms |
2648 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2652 KB |
answer = YES |
33 |
Correct |
1 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2648 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
37 |
Correct |
2 ms |
2648 KB |
answer = YES |
38 |
Correct |
3 ms |
2652 KB |
answer = YES |
39 |
Correct |
3 ms |
2652 KB |
answer = YES |
40 |
Correct |
4 ms |
2908 KB |
answer = YES |
41 |
Correct |
3 ms |
2908 KB |
answer = NO |
42 |
Correct |
4 ms |
2908 KB |
answer = YES |
43 |
Correct |
4 ms |
2660 KB |
answer = YES |
44 |
Correct |
4 ms |
2652 KB |
answer = YES |
45 |
Correct |
2 ms |
2652 KB |
answer = YES |
46 |
Correct |
2 ms |
2648 KB |
answer = YES |
47 |
Correct |
2 ms |
2652 KB |
answer = YES |
48 |
Correct |
2 ms |
2908 KB |
answer = YES |
49 |
Correct |
44 ms |
3876 KB |
answer = YES |
50 |
Correct |
38 ms |
4140 KB |
answer = YES |
51 |
Correct |
34 ms |
4320 KB |
answer = YES |
52 |
Correct |
36 ms |
4284 KB |
answer = NO |
53 |
Correct |
4 ms |
2904 KB |
answer = YES |
54 |
Correct |
8 ms |
2908 KB |
answer = YES |
55 |
Correct |
19 ms |
3356 KB |
answer = YES |
56 |
Correct |
35 ms |
3800 KB |
answer = YES |
57 |
Correct |
30 ms |
3420 KB |
answer = YES |
58 |
Correct |
28 ms |
3548 KB |
answer = YES |
59 |
Correct |
10 ms |
3420 KB |
answer = YES |
60 |
Correct |
33 ms |
3628 KB |
answer = YES |
61 |
Correct |
6 ms |
3420 KB |
answer = YES |
62 |
Correct |
99 ms |
8424 KB |
answer = NO |
63 |
Correct |
104 ms |
8308 KB |
answer = YES |
64 |
Correct |
111 ms |
8272 KB |
answer = NO |
65 |
Correct |
109 ms |
8452 KB |
answer = YES |
66 |
Correct |
6 ms |
2908 KB |
answer = YES |
67 |
Correct |
349 ms |
19912 KB |
answer = YES |
68 |
Correct |
413 ms |
20608 KB |
answer = YES |
69 |
Correct |
393 ms |
21688 KB |
answer = YES |
70 |
Correct |
628 ms |
24800 KB |
answer = YES |
71 |
Correct |
417 ms |
23052 KB |
answer = YES |
72 |
Correct |
427 ms |
14504 KB |
answer = YES |
73 |
Correct |
427 ms |
14020 KB |
answer = YES |
74 |
Correct |
260 ms |
14676 KB |
answer = YES |
75 |
Correct |
284 ms |
12656 KB |
answer = NO |
76 |
Correct |
54 ms |
4208 KB |
answer = YES |
77 |
Correct |
91 ms |
5608 KB |
answer = YES |
78 |
Correct |
194 ms |
7948 KB |
answer = YES |
79 |
Correct |
360 ms |
13064 KB |
answer = YES |
80 |
Incorrect |
292 ms |
14812 KB |
participant answer is larger than the answer of jury |
81 |
Halted |
0 ms |
0 KB |
- |