# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1105878 |
2024-10-28T08:29:54 Z |
DangKhoizzzz |
Graph (BOI20_graph) |
C++14 |
|
122 ms |
30168 KB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair <int , int> pii;
const int maxn = 2e5 + 7;
int n , m;
double ans[maxn];
vector <pii> g[maxn];
bool vis[maxn];
pair <double , double> val[maxn];
vector <int> node;
bool conf;
double found;
void dfs(int u , int p)
{
vis[u] = 1;
node.push_back(u);
for(pii tmp: g[u])
{
int v = tmp.fi;
int w = tmp.se;
if(v == p) continue;
if(!vis[v])
{
val[v].fi = -1*val[u].fi;
val[v].se = w - val[u].se;
dfs(v , u);
}
else if(val[v].fi == val[u].fi)
{
conf = 1;
found = (1.0*(w - val[v].se - val[u].se)/2.0)*val[v].fi;
}
}
}
void solve()
{
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int u , v , w;
cin >> u >> v >> w;
g[u].push_back({v , w});
g[v].push_back({u , w});
}
for(int i = 1; i <= n; i++)
{
if(!vis[i])
{
node.clear();
conf = 0;
val[i].fi = 1.0;
val[i].se = 0.0;
dfs(i , 0);
if(conf == 0)
{
vector <int> v;
for(int u: node)
{
if(val[u].fi < 0) v.push_back(val[u].se);
else v.push_back(val[u].se*-1.0);
}
sort(v.begin() , v.end());
found = v[((int)(v.size()) - 1)/2];
//cout << found << '\n';
}
for(int u: node)
{
ans[u] = found*val[u].fi + val[u].se;
}
}
}
for(int u = 1; u <= n; u++)
{
for(pii tmp: g[u])
{
int v = tmp.fi;
int w = tmp.se;
if(ans[u] + ans[v] != w)
{
cout << "NO" << '\n';
return;
}
}
}
cout << "YES" << '\n';
for(int u = 1; u <= n; u++) cout << ans[u] << ' ';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
//freopen("sol.inp" ,"r" , stdin);
//freopen("sol.out" , "w" , stdout);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
answer = YES |
2 |
Correct |
2 ms |
6652 KB |
answer = YES |
3 |
Correct |
2 ms |
6620 KB |
answer = YES |
4 |
Correct |
1 ms |
6480 KB |
answer = NO |
5 |
Correct |
2 ms |
6480 KB |
answer = YES |
6 |
Correct |
1 ms |
6480 KB |
answer = YES |
7 |
Correct |
2 ms |
6480 KB |
answer = YES |
8 |
Correct |
2 ms |
6480 KB |
answer = YES |
9 |
Correct |
1 ms |
6628 KB |
answer = NO |
10 |
Correct |
3 ms |
6480 KB |
answer = YES |
11 |
Correct |
3 ms |
6480 KB |
answer = YES |
12 |
Correct |
2 ms |
6480 KB |
answer = NO |
13 |
Correct |
2 ms |
6480 KB |
answer = YES |
14 |
Correct |
2 ms |
6480 KB |
answer = YES |
15 |
Correct |
2 ms |
6480 KB |
answer = YES |
16 |
Correct |
2 ms |
6480 KB |
answer = YES |
17 |
Correct |
2 ms |
6480 KB |
answer = YES |
18 |
Correct |
2 ms |
6628 KB |
answer = YES |
19 |
Correct |
2 ms |
6480 KB |
answer = YES |
20 |
Correct |
2 ms |
6480 KB |
answer = YES |
21 |
Correct |
2 ms |
6480 KB |
answer = YES |
22 |
Correct |
2 ms |
6480 KB |
answer = NO |
23 |
Correct |
2 ms |
6480 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
answer = YES |
2 |
Correct |
2 ms |
6652 KB |
answer = YES |
3 |
Correct |
2 ms |
6620 KB |
answer = YES |
4 |
Correct |
1 ms |
6480 KB |
answer = NO |
5 |
Correct |
2 ms |
6480 KB |
answer = YES |
6 |
Correct |
1 ms |
6480 KB |
answer = YES |
7 |
Correct |
2 ms |
6480 KB |
answer = YES |
8 |
Correct |
2 ms |
6480 KB |
answer = YES |
9 |
Correct |
1 ms |
6628 KB |
answer = NO |
10 |
Correct |
3 ms |
6480 KB |
answer = YES |
11 |
Correct |
3 ms |
6480 KB |
answer = YES |
12 |
Correct |
2 ms |
6480 KB |
answer = NO |
13 |
Correct |
2 ms |
6480 KB |
answer = YES |
14 |
Correct |
2 ms |
6480 KB |
answer = YES |
15 |
Correct |
2 ms |
6480 KB |
answer = YES |
16 |
Correct |
2 ms |
6480 KB |
answer = YES |
17 |
Correct |
2 ms |
6480 KB |
answer = YES |
18 |
Correct |
2 ms |
6628 KB |
answer = YES |
19 |
Correct |
2 ms |
6480 KB |
answer = YES |
20 |
Correct |
2 ms |
6480 KB |
answer = YES |
21 |
Correct |
2 ms |
6480 KB |
answer = YES |
22 |
Correct |
2 ms |
6480 KB |
answer = NO |
23 |
Correct |
2 ms |
6480 KB |
answer = NO |
24 |
Correct |
2 ms |
6480 KB |
answer = YES |
25 |
Correct |
2 ms |
6628 KB |
answer = YES |
26 |
Correct |
2 ms |
6480 KB |
answer = YES |
27 |
Correct |
2 ms |
6480 KB |
answer = YES |
28 |
Correct |
2 ms |
6480 KB |
answer = YES |
29 |
Correct |
2 ms |
6480 KB |
answer = YES |
30 |
Correct |
2 ms |
6480 KB |
answer = NO |
31 |
Correct |
2 ms |
6480 KB |
answer = YES |
32 |
Correct |
2 ms |
6480 KB |
answer = YES |
33 |
Correct |
2 ms |
6568 KB |
answer = YES |
34 |
Correct |
2 ms |
6480 KB |
answer = YES |
35 |
Correct |
2 ms |
6480 KB |
answer = YES |
36 |
Correct |
2 ms |
6480 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
answer = YES |
2 |
Correct |
2 ms |
6652 KB |
answer = YES |
3 |
Correct |
2 ms |
6620 KB |
answer = YES |
4 |
Correct |
1 ms |
6480 KB |
answer = NO |
5 |
Correct |
2 ms |
6480 KB |
answer = YES |
6 |
Correct |
1 ms |
6480 KB |
answer = YES |
7 |
Correct |
2 ms |
6480 KB |
answer = YES |
8 |
Correct |
2 ms |
6480 KB |
answer = YES |
9 |
Correct |
1 ms |
6628 KB |
answer = NO |
10 |
Correct |
3 ms |
6480 KB |
answer = YES |
11 |
Correct |
3 ms |
6480 KB |
answer = YES |
12 |
Correct |
2 ms |
6480 KB |
answer = NO |
13 |
Correct |
2 ms |
6480 KB |
answer = YES |
14 |
Correct |
2 ms |
6480 KB |
answer = YES |
15 |
Correct |
2 ms |
6480 KB |
answer = YES |
16 |
Correct |
2 ms |
6480 KB |
answer = YES |
17 |
Correct |
2 ms |
6480 KB |
answer = YES |
18 |
Correct |
2 ms |
6628 KB |
answer = YES |
19 |
Correct |
2 ms |
6480 KB |
answer = YES |
20 |
Correct |
2 ms |
6480 KB |
answer = YES |
21 |
Correct |
2 ms |
6480 KB |
answer = YES |
22 |
Correct |
2 ms |
6480 KB |
answer = NO |
23 |
Correct |
2 ms |
6480 KB |
answer = NO |
24 |
Correct |
2 ms |
6480 KB |
answer = YES |
25 |
Correct |
2 ms |
6628 KB |
answer = YES |
26 |
Correct |
2 ms |
6480 KB |
answer = YES |
27 |
Correct |
2 ms |
6480 KB |
answer = YES |
28 |
Correct |
2 ms |
6480 KB |
answer = YES |
29 |
Correct |
2 ms |
6480 KB |
answer = YES |
30 |
Correct |
2 ms |
6480 KB |
answer = NO |
31 |
Correct |
2 ms |
6480 KB |
answer = YES |
32 |
Correct |
2 ms |
6480 KB |
answer = YES |
33 |
Correct |
2 ms |
6568 KB |
answer = YES |
34 |
Correct |
2 ms |
6480 KB |
answer = YES |
35 |
Correct |
2 ms |
6480 KB |
answer = YES |
36 |
Correct |
2 ms |
6480 KB |
answer = YES |
37 |
Correct |
2 ms |
6480 KB |
answer = YES |
38 |
Correct |
2 ms |
6480 KB |
answer = YES |
39 |
Correct |
3 ms |
6692 KB |
answer = YES |
40 |
Correct |
3 ms |
6652 KB |
answer = YES |
41 |
Correct |
2 ms |
6480 KB |
answer = NO |
42 |
Correct |
3 ms |
6736 KB |
answer = YES |
43 |
Correct |
3 ms |
6480 KB |
answer = YES |
44 |
Correct |
2 ms |
6480 KB |
answer = YES |
45 |
Correct |
3 ms |
6480 KB |
answer = YES |
46 |
Correct |
2 ms |
6480 KB |
answer = YES |
47 |
Correct |
3 ms |
6480 KB |
answer = YES |
48 |
Correct |
3 ms |
6480 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
answer = YES |
2 |
Correct |
2 ms |
6652 KB |
answer = YES |
3 |
Correct |
2 ms |
6620 KB |
answer = YES |
4 |
Correct |
1 ms |
6480 KB |
answer = NO |
5 |
Correct |
2 ms |
6480 KB |
answer = YES |
6 |
Correct |
1 ms |
6480 KB |
answer = YES |
7 |
Correct |
2 ms |
6480 KB |
answer = YES |
8 |
Correct |
2 ms |
6480 KB |
answer = YES |
9 |
Correct |
1 ms |
6628 KB |
answer = NO |
10 |
Correct |
3 ms |
6480 KB |
answer = YES |
11 |
Correct |
3 ms |
6480 KB |
answer = YES |
12 |
Correct |
2 ms |
6480 KB |
answer = NO |
13 |
Correct |
2 ms |
6480 KB |
answer = YES |
14 |
Correct |
2 ms |
6480 KB |
answer = YES |
15 |
Correct |
2 ms |
6480 KB |
answer = YES |
16 |
Correct |
2 ms |
6480 KB |
answer = YES |
17 |
Correct |
2 ms |
6480 KB |
answer = YES |
18 |
Correct |
2 ms |
6628 KB |
answer = YES |
19 |
Correct |
2 ms |
6480 KB |
answer = YES |
20 |
Correct |
2 ms |
6480 KB |
answer = YES |
21 |
Correct |
2 ms |
6480 KB |
answer = YES |
22 |
Correct |
2 ms |
6480 KB |
answer = NO |
23 |
Correct |
2 ms |
6480 KB |
answer = NO |
24 |
Correct |
2 ms |
6480 KB |
answer = YES |
25 |
Correct |
2 ms |
6628 KB |
answer = YES |
26 |
Correct |
2 ms |
6480 KB |
answer = YES |
27 |
Correct |
2 ms |
6480 KB |
answer = YES |
28 |
Correct |
2 ms |
6480 KB |
answer = YES |
29 |
Correct |
2 ms |
6480 KB |
answer = YES |
30 |
Correct |
2 ms |
6480 KB |
answer = NO |
31 |
Correct |
2 ms |
6480 KB |
answer = YES |
32 |
Correct |
2 ms |
6480 KB |
answer = YES |
33 |
Correct |
2 ms |
6568 KB |
answer = YES |
34 |
Correct |
2 ms |
6480 KB |
answer = YES |
35 |
Correct |
2 ms |
6480 KB |
answer = YES |
36 |
Correct |
2 ms |
6480 KB |
answer = YES |
37 |
Correct |
2 ms |
6480 KB |
answer = YES |
38 |
Correct |
2 ms |
6480 KB |
answer = YES |
39 |
Correct |
3 ms |
6692 KB |
answer = YES |
40 |
Correct |
3 ms |
6652 KB |
answer = YES |
41 |
Correct |
2 ms |
6480 KB |
answer = NO |
42 |
Correct |
3 ms |
6736 KB |
answer = YES |
43 |
Correct |
3 ms |
6480 KB |
answer = YES |
44 |
Correct |
2 ms |
6480 KB |
answer = YES |
45 |
Correct |
3 ms |
6480 KB |
answer = YES |
46 |
Correct |
2 ms |
6480 KB |
answer = YES |
47 |
Correct |
3 ms |
6480 KB |
answer = YES |
48 |
Correct |
3 ms |
6480 KB |
answer = YES |
49 |
Correct |
8 ms |
7504 KB |
answer = YES |
50 |
Correct |
9 ms |
7760 KB |
answer = YES |
51 |
Correct |
8 ms |
7936 KB |
answer = YES |
52 |
Correct |
5 ms |
7760 KB |
answer = NO |
53 |
Correct |
2 ms |
6912 KB |
answer = YES |
54 |
Correct |
3 ms |
6736 KB |
answer = YES |
55 |
Correct |
4 ms |
7144 KB |
answer = YES |
56 |
Correct |
7 ms |
7572 KB |
answer = YES |
57 |
Correct |
7 ms |
7248 KB |
answer = YES |
58 |
Correct |
6 ms |
7504 KB |
answer = YES |
59 |
Correct |
7 ms |
7248 KB |
answer = YES |
60 |
Correct |
7 ms |
7504 KB |
answer = YES |
61 |
Correct |
4 ms |
6992 KB |
answer = YES |
62 |
Correct |
48 ms |
18760 KB |
answer = NO |
63 |
Correct |
57 ms |
18760 KB |
answer = YES |
64 |
Correct |
50 ms |
18756 KB |
answer = NO |
65 |
Correct |
53 ms |
18736 KB |
answer = YES |
66 |
Correct |
4 ms |
6736 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
answer = YES |
2 |
Correct |
2 ms |
6652 KB |
answer = YES |
3 |
Correct |
2 ms |
6620 KB |
answer = YES |
4 |
Correct |
1 ms |
6480 KB |
answer = NO |
5 |
Correct |
2 ms |
6480 KB |
answer = YES |
6 |
Correct |
1 ms |
6480 KB |
answer = YES |
7 |
Correct |
2 ms |
6480 KB |
answer = YES |
8 |
Correct |
2 ms |
6480 KB |
answer = YES |
9 |
Correct |
1 ms |
6628 KB |
answer = NO |
10 |
Correct |
3 ms |
6480 KB |
answer = YES |
11 |
Correct |
3 ms |
6480 KB |
answer = YES |
12 |
Correct |
2 ms |
6480 KB |
answer = NO |
13 |
Correct |
2 ms |
6480 KB |
answer = YES |
14 |
Correct |
2 ms |
6480 KB |
answer = YES |
15 |
Correct |
2 ms |
6480 KB |
answer = YES |
16 |
Correct |
2 ms |
6480 KB |
answer = YES |
17 |
Correct |
2 ms |
6480 KB |
answer = YES |
18 |
Correct |
2 ms |
6628 KB |
answer = YES |
19 |
Correct |
2 ms |
6480 KB |
answer = YES |
20 |
Correct |
2 ms |
6480 KB |
answer = YES |
21 |
Correct |
2 ms |
6480 KB |
answer = YES |
22 |
Correct |
2 ms |
6480 KB |
answer = NO |
23 |
Correct |
2 ms |
6480 KB |
answer = NO |
24 |
Correct |
2 ms |
6480 KB |
answer = YES |
25 |
Correct |
2 ms |
6628 KB |
answer = YES |
26 |
Correct |
2 ms |
6480 KB |
answer = YES |
27 |
Correct |
2 ms |
6480 KB |
answer = YES |
28 |
Correct |
2 ms |
6480 KB |
answer = YES |
29 |
Correct |
2 ms |
6480 KB |
answer = YES |
30 |
Correct |
2 ms |
6480 KB |
answer = NO |
31 |
Correct |
2 ms |
6480 KB |
answer = YES |
32 |
Correct |
2 ms |
6480 KB |
answer = YES |
33 |
Correct |
2 ms |
6568 KB |
answer = YES |
34 |
Correct |
2 ms |
6480 KB |
answer = YES |
35 |
Correct |
2 ms |
6480 KB |
answer = YES |
36 |
Correct |
2 ms |
6480 KB |
answer = YES |
37 |
Correct |
2 ms |
6480 KB |
answer = YES |
38 |
Correct |
2 ms |
6480 KB |
answer = YES |
39 |
Correct |
3 ms |
6692 KB |
answer = YES |
40 |
Correct |
3 ms |
6652 KB |
answer = YES |
41 |
Correct |
2 ms |
6480 KB |
answer = NO |
42 |
Correct |
3 ms |
6736 KB |
answer = YES |
43 |
Correct |
3 ms |
6480 KB |
answer = YES |
44 |
Correct |
2 ms |
6480 KB |
answer = YES |
45 |
Correct |
3 ms |
6480 KB |
answer = YES |
46 |
Correct |
2 ms |
6480 KB |
answer = YES |
47 |
Correct |
3 ms |
6480 KB |
answer = YES |
48 |
Correct |
3 ms |
6480 KB |
answer = YES |
49 |
Correct |
8 ms |
7504 KB |
answer = YES |
50 |
Correct |
9 ms |
7760 KB |
answer = YES |
51 |
Correct |
8 ms |
7936 KB |
answer = YES |
52 |
Correct |
5 ms |
7760 KB |
answer = NO |
53 |
Correct |
2 ms |
6912 KB |
answer = YES |
54 |
Correct |
3 ms |
6736 KB |
answer = YES |
55 |
Correct |
4 ms |
7144 KB |
answer = YES |
56 |
Correct |
7 ms |
7572 KB |
answer = YES |
57 |
Correct |
7 ms |
7248 KB |
answer = YES |
58 |
Correct |
6 ms |
7504 KB |
answer = YES |
59 |
Correct |
7 ms |
7248 KB |
answer = YES |
60 |
Correct |
7 ms |
7504 KB |
answer = YES |
61 |
Correct |
4 ms |
6992 KB |
answer = YES |
62 |
Correct |
48 ms |
18760 KB |
answer = NO |
63 |
Correct |
57 ms |
18760 KB |
answer = YES |
64 |
Correct |
50 ms |
18756 KB |
answer = NO |
65 |
Correct |
53 ms |
18736 KB |
answer = YES |
66 |
Correct |
4 ms |
6736 KB |
answer = YES |
67 |
Correct |
64 ms |
23228 KB |
answer = YES |
68 |
Correct |
74 ms |
23236 KB |
answer = YES |
69 |
Correct |
57 ms |
22664 KB |
answer = YES |
70 |
Correct |
82 ms |
30168 KB |
answer = YES |
71 |
Correct |
62 ms |
22716 KB |
answer = YES |
72 |
Correct |
69 ms |
17644 KB |
answer = YES |
73 |
Correct |
76 ms |
16704 KB |
answer = YES |
74 |
Correct |
43 ms |
16984 KB |
answer = YES |
75 |
Correct |
26 ms |
17148 KB |
answer = NO |
76 |
Correct |
14 ms |
10064 KB |
answer = YES |
77 |
Correct |
19 ms |
10960 KB |
answer = YES |
78 |
Correct |
26 ms |
12488 KB |
answer = YES |
79 |
Correct |
51 ms |
16400 KB |
answer = YES |
80 |
Correct |
44 ms |
17100 KB |
answer = YES |
81 |
Correct |
31 ms |
19328 KB |
answer = NO |
82 |
Correct |
73 ms |
22436 KB |
answer = YES |
83 |
Correct |
75 ms |
23264 KB |
answer = YES |
84 |
Correct |
81 ms |
23816 KB |
answer = YES |
85 |
Correct |
59 ms |
23300 KB |
answer = YES |
86 |
Correct |
67 ms |
22772 KB |
answer = YES |
87 |
Correct |
43 ms |
18532 KB |
answer = NO |
88 |
Correct |
74 ms |
19388 KB |
answer = YES |
89 |
Correct |
77 ms |
15604 KB |
answer = YES |
90 |
Correct |
63 ms |
15376 KB |
answer = YES |
91 |
Correct |
72 ms |
16160 KB |
answer = YES |
92 |
Correct |
32 ms |
12744 KB |
answer = YES |
93 |
Correct |
43 ms |
12736 KB |
answer = YES |
94 |
Correct |
58 ms |
23996 KB |
answer = NO |
95 |
Correct |
36 ms |
15688 KB |
answer = NO |
96 |
Correct |
122 ms |
27272 KB |
answer = YES |
97 |
Correct |
36 ms |
23228 KB |
answer = NO |