# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102678 |
2024-10-18T15:32:01 Z |
alexdd |
Graph (BOI20_graph) |
C++17 |
|
174 ms |
40952 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long
#define double long double
const int INF = 1e14;
int n,m;
double val[100005];
int u[200005],v[200005],s[200005];
vector<pair<int,int>> con[100005];
bool visited[100005];
bool bun;
double cur;
vector<int> aux;
vector<pair<double,int>> v0;
int parte[100005];
void dfs(int nod)
{
if(parte[nod]==0) v0.push_back({val[nod],nod});
else v0.push_back({-val[nod],nod});
aux.push_back(nod);
visited[nod]=1;
for(auto [adj,sum]:con[nod])
{
if(!visited[adj])
{
val[adj] = sum - val[nod];
dfs(adj);
}
else if(val[adj] != sum - val[nod])
bun = 0;
}
}
bool isbipartit;
pair<int,int> parent[100005];
int cap1,cap2,scap;
void dfs_bipartit(int nod)
{
for(auto [adj,c]:con[nod])
{
if(parte[adj]==-1)
{
parte[adj] = 1-parte[nod];
parent[adj] = {nod,c};
dfs_bipartit(adj);
}
else if(parte[adj] != 1-parte[nod])
{
isbipartit=0;
cap1 = adj;
cap2 = nod;
scap = c;
}
}
}
bool verif_bipartit(int nod)
{
parte[nod]=0;
isbipartit=1;
dfs_bipartit(nod);
if(!isbipartit)
{
int cur=cap1;
double sum=scap,sum2=0;
int pas=0;
while(cur!=cap2)
{
if(pas==0)
{
sum2 += parent[cur].second;
}
pas = 1-pas;
sum += parent[cur].second;
cur = parent[cur].first;
}
sum/=2;
val[cap2] = sum - sum2;
bun=1;
dfs(cap2);
if(!bun)
{
cout<<"NO";
exit(0);
}
}
return isbipartit;
}
vector<double> possible;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
for(double i=-100;i<=100;i+=0.5)
possible.push_back(i);
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>u[i]>>v[i]>>s[i];
con[u[i]].push_back({v[i],s[i]});
con[v[i]].push_back({u[i],s[i]});
}
for(int i=1;i<=n;i++)
{
parte[i]=-1;
visited[i]=0;
}
for(int i=1;i<=n;i++)
{
if(!visited[i])
{
if(verif_bipartit(i))
{
bun=1;
val[i]=0;
v0.clear();
dfs(i);
if(!bun)
{
cout<<"NO";
return 0;
}
double mnm=INF,unde;
for(double x:possible)
{
double cur=0;
for(auto [y,id]:v0)
cur += abs(y+x);
if(cur < mnm)
{
mnm = cur;
unde = x;
}
}
for(auto [y,id]:v0)
{
if(parte[id]==0) val[id] += unde;
else val[id] -= unde;
}
}
}
}
cout<<"YES\n";
for(int i=1;i<=n;i++)
cout<<val[i]<<" ";
return 0;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:136:34: warning: 'unde' may be used uninitialized in this function [-Wmaybe-uninitialized]
136 | else val[id] -= unde;
| ~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10576 KB |
answer = YES |
2 |
Correct |
2 ms |
10576 KB |
answer = YES |
3 |
Correct |
2 ms |
10748 KB |
answer = YES |
4 |
Correct |
2 ms |
10576 KB |
answer = NO |
5 |
Correct |
2 ms |
10576 KB |
answer = YES |
6 |
Correct |
2 ms |
10576 KB |
answer = YES |
7 |
Correct |
2 ms |
10576 KB |
answer = YES |
8 |
Correct |
2 ms |
10576 KB |
answer = YES |
9 |
Correct |
2 ms |
10576 KB |
answer = NO |
10 |
Correct |
3 ms |
10576 KB |
answer = YES |
11 |
Correct |
2 ms |
10732 KB |
answer = YES |
12 |
Correct |
2 ms |
10676 KB |
answer = NO |
13 |
Correct |
2 ms |
10576 KB |
answer = YES |
14 |
Correct |
2 ms |
10576 KB |
answer = YES |
15 |
Correct |
2 ms |
10576 KB |
answer = YES |
16 |
Correct |
2 ms |
10576 KB |
answer = YES |
17 |
Correct |
2 ms |
8528 KB |
answer = YES |
18 |
Correct |
2 ms |
10576 KB |
answer = YES |
19 |
Correct |
2 ms |
10576 KB |
answer = YES |
20 |
Correct |
2 ms |
10576 KB |
answer = YES |
21 |
Correct |
2 ms |
10740 KB |
answer = YES |
22 |
Correct |
2 ms |
10576 KB |
answer = NO |
23 |
Correct |
2 ms |
10576 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10576 KB |
answer = YES |
2 |
Correct |
2 ms |
10576 KB |
answer = YES |
3 |
Correct |
2 ms |
10748 KB |
answer = YES |
4 |
Correct |
2 ms |
10576 KB |
answer = NO |
5 |
Correct |
2 ms |
10576 KB |
answer = YES |
6 |
Correct |
2 ms |
10576 KB |
answer = YES |
7 |
Correct |
2 ms |
10576 KB |
answer = YES |
8 |
Correct |
2 ms |
10576 KB |
answer = YES |
9 |
Correct |
2 ms |
10576 KB |
answer = NO |
10 |
Correct |
3 ms |
10576 KB |
answer = YES |
11 |
Correct |
2 ms |
10732 KB |
answer = YES |
12 |
Correct |
2 ms |
10676 KB |
answer = NO |
13 |
Correct |
2 ms |
10576 KB |
answer = YES |
14 |
Correct |
2 ms |
10576 KB |
answer = YES |
15 |
Correct |
2 ms |
10576 KB |
answer = YES |
16 |
Correct |
2 ms |
10576 KB |
answer = YES |
17 |
Correct |
2 ms |
8528 KB |
answer = YES |
18 |
Correct |
2 ms |
10576 KB |
answer = YES |
19 |
Correct |
2 ms |
10576 KB |
answer = YES |
20 |
Correct |
2 ms |
10576 KB |
answer = YES |
21 |
Correct |
2 ms |
10740 KB |
answer = YES |
22 |
Correct |
2 ms |
10576 KB |
answer = NO |
23 |
Correct |
2 ms |
10576 KB |
answer = NO |
24 |
Correct |
2 ms |
10576 KB |
answer = YES |
25 |
Correct |
2 ms |
10588 KB |
answer = YES |
26 |
Correct |
2 ms |
10576 KB |
answer = YES |
27 |
Correct |
2 ms |
10748 KB |
answer = YES |
28 |
Correct |
2 ms |
10576 KB |
answer = YES |
29 |
Correct |
3 ms |
10576 KB |
answer = YES |
30 |
Correct |
2 ms |
10576 KB |
answer = NO |
31 |
Correct |
2 ms |
10576 KB |
answer = YES |
32 |
Correct |
2 ms |
10744 KB |
answer = YES |
33 |
Correct |
2 ms |
10576 KB |
answer = YES |
34 |
Correct |
2 ms |
10576 KB |
answer = YES |
35 |
Correct |
2 ms |
10576 KB |
answer = YES |
36 |
Correct |
2 ms |
10676 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10576 KB |
answer = YES |
2 |
Correct |
2 ms |
10576 KB |
answer = YES |
3 |
Correct |
2 ms |
10748 KB |
answer = YES |
4 |
Correct |
2 ms |
10576 KB |
answer = NO |
5 |
Correct |
2 ms |
10576 KB |
answer = YES |
6 |
Correct |
2 ms |
10576 KB |
answer = YES |
7 |
Correct |
2 ms |
10576 KB |
answer = YES |
8 |
Correct |
2 ms |
10576 KB |
answer = YES |
9 |
Correct |
2 ms |
10576 KB |
answer = NO |
10 |
Correct |
3 ms |
10576 KB |
answer = YES |
11 |
Correct |
2 ms |
10732 KB |
answer = YES |
12 |
Correct |
2 ms |
10676 KB |
answer = NO |
13 |
Correct |
2 ms |
10576 KB |
answer = YES |
14 |
Correct |
2 ms |
10576 KB |
answer = YES |
15 |
Correct |
2 ms |
10576 KB |
answer = YES |
16 |
Correct |
2 ms |
10576 KB |
answer = YES |
17 |
Correct |
2 ms |
8528 KB |
answer = YES |
18 |
Correct |
2 ms |
10576 KB |
answer = YES |
19 |
Correct |
2 ms |
10576 KB |
answer = YES |
20 |
Correct |
2 ms |
10576 KB |
answer = YES |
21 |
Correct |
2 ms |
10740 KB |
answer = YES |
22 |
Correct |
2 ms |
10576 KB |
answer = NO |
23 |
Correct |
2 ms |
10576 KB |
answer = NO |
24 |
Correct |
2 ms |
10576 KB |
answer = YES |
25 |
Correct |
2 ms |
10588 KB |
answer = YES |
26 |
Correct |
2 ms |
10576 KB |
answer = YES |
27 |
Correct |
2 ms |
10748 KB |
answer = YES |
28 |
Correct |
2 ms |
10576 KB |
answer = YES |
29 |
Correct |
3 ms |
10576 KB |
answer = YES |
30 |
Correct |
2 ms |
10576 KB |
answer = NO |
31 |
Correct |
2 ms |
10576 KB |
answer = YES |
32 |
Correct |
2 ms |
10744 KB |
answer = YES |
33 |
Correct |
2 ms |
10576 KB |
answer = YES |
34 |
Correct |
2 ms |
10576 KB |
answer = YES |
35 |
Correct |
2 ms |
10576 KB |
answer = YES |
36 |
Correct |
2 ms |
10676 KB |
answer = YES |
37 |
Correct |
3 ms |
10576 KB |
answer = YES |
38 |
Correct |
2 ms |
10576 KB |
answer = YES |
39 |
Correct |
3 ms |
10576 KB |
answer = YES |
40 |
Correct |
3 ms |
10832 KB |
answer = YES |
41 |
Correct |
3 ms |
10832 KB |
answer = NO |
42 |
Correct |
3 ms |
10832 KB |
answer = YES |
43 |
Correct |
4 ms |
10832 KB |
answer = YES |
44 |
Correct |
4 ms |
10832 KB |
answer = YES |
45 |
Correct |
4 ms |
10888 KB |
answer = YES |
46 |
Correct |
3 ms |
10576 KB |
answer = YES |
47 |
Correct |
3 ms |
10832 KB |
answer = YES |
48 |
Correct |
3 ms |
10832 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10576 KB |
answer = YES |
2 |
Correct |
2 ms |
10576 KB |
answer = YES |
3 |
Correct |
2 ms |
10748 KB |
answer = YES |
4 |
Correct |
2 ms |
10576 KB |
answer = NO |
5 |
Correct |
2 ms |
10576 KB |
answer = YES |
6 |
Correct |
2 ms |
10576 KB |
answer = YES |
7 |
Correct |
2 ms |
10576 KB |
answer = YES |
8 |
Correct |
2 ms |
10576 KB |
answer = YES |
9 |
Correct |
2 ms |
10576 KB |
answer = NO |
10 |
Correct |
3 ms |
10576 KB |
answer = YES |
11 |
Correct |
2 ms |
10732 KB |
answer = YES |
12 |
Correct |
2 ms |
10676 KB |
answer = NO |
13 |
Correct |
2 ms |
10576 KB |
answer = YES |
14 |
Correct |
2 ms |
10576 KB |
answer = YES |
15 |
Correct |
2 ms |
10576 KB |
answer = YES |
16 |
Correct |
2 ms |
10576 KB |
answer = YES |
17 |
Correct |
2 ms |
8528 KB |
answer = YES |
18 |
Correct |
2 ms |
10576 KB |
answer = YES |
19 |
Correct |
2 ms |
10576 KB |
answer = YES |
20 |
Correct |
2 ms |
10576 KB |
answer = YES |
21 |
Correct |
2 ms |
10740 KB |
answer = YES |
22 |
Correct |
2 ms |
10576 KB |
answer = NO |
23 |
Correct |
2 ms |
10576 KB |
answer = NO |
24 |
Correct |
2 ms |
10576 KB |
answer = YES |
25 |
Correct |
2 ms |
10588 KB |
answer = YES |
26 |
Correct |
2 ms |
10576 KB |
answer = YES |
27 |
Correct |
2 ms |
10748 KB |
answer = YES |
28 |
Correct |
2 ms |
10576 KB |
answer = YES |
29 |
Correct |
3 ms |
10576 KB |
answer = YES |
30 |
Correct |
2 ms |
10576 KB |
answer = NO |
31 |
Correct |
2 ms |
10576 KB |
answer = YES |
32 |
Correct |
2 ms |
10744 KB |
answer = YES |
33 |
Correct |
2 ms |
10576 KB |
answer = YES |
34 |
Correct |
2 ms |
10576 KB |
answer = YES |
35 |
Correct |
2 ms |
10576 KB |
answer = YES |
36 |
Correct |
2 ms |
10676 KB |
answer = YES |
37 |
Correct |
3 ms |
10576 KB |
answer = YES |
38 |
Correct |
2 ms |
10576 KB |
answer = YES |
39 |
Correct |
3 ms |
10576 KB |
answer = YES |
40 |
Correct |
3 ms |
10832 KB |
answer = YES |
41 |
Correct |
3 ms |
10832 KB |
answer = NO |
42 |
Correct |
3 ms |
10832 KB |
answer = YES |
43 |
Correct |
4 ms |
10832 KB |
answer = YES |
44 |
Correct |
4 ms |
10832 KB |
answer = YES |
45 |
Correct |
4 ms |
10888 KB |
answer = YES |
46 |
Correct |
3 ms |
10576 KB |
answer = YES |
47 |
Correct |
3 ms |
10832 KB |
answer = YES |
48 |
Correct |
3 ms |
10832 KB |
answer = YES |
49 |
Correct |
20 ms |
12092 KB |
answer = YES |
50 |
Correct |
9 ms |
12656 KB |
answer = YES |
51 |
Correct |
22 ms |
12492 KB |
answer = YES |
52 |
Correct |
7 ms |
12492 KB |
answer = NO |
53 |
Correct |
4 ms |
10832 KB |
answer = YES |
54 |
Correct |
5 ms |
11100 KB |
answer = YES |
55 |
Correct |
9 ms |
11344 KB |
answer = YES |
56 |
Correct |
20 ms |
12020 KB |
answer = YES |
57 |
Correct |
18 ms |
11600 KB |
answer = YES |
58 |
Correct |
15 ms |
11600 KB |
answer = YES |
59 |
Correct |
8 ms |
11980 KB |
answer = YES |
60 |
Correct |
17 ms |
11792 KB |
answer = YES |
61 |
Correct |
5 ms |
11344 KB |
answer = YES |
62 |
Correct |
51 ms |
21276 KB |
answer = NO |
63 |
Correct |
57 ms |
21256 KB |
answer = YES |
64 |
Correct |
62 ms |
21260 KB |
answer = NO |
65 |
Correct |
54 ms |
21256 KB |
answer = YES |
66 |
Correct |
5 ms |
10832 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10576 KB |
answer = YES |
2 |
Correct |
2 ms |
10576 KB |
answer = YES |
3 |
Correct |
2 ms |
10748 KB |
answer = YES |
4 |
Correct |
2 ms |
10576 KB |
answer = NO |
5 |
Correct |
2 ms |
10576 KB |
answer = YES |
6 |
Correct |
2 ms |
10576 KB |
answer = YES |
7 |
Correct |
2 ms |
10576 KB |
answer = YES |
8 |
Correct |
2 ms |
10576 KB |
answer = YES |
9 |
Correct |
2 ms |
10576 KB |
answer = NO |
10 |
Correct |
3 ms |
10576 KB |
answer = YES |
11 |
Correct |
2 ms |
10732 KB |
answer = YES |
12 |
Correct |
2 ms |
10676 KB |
answer = NO |
13 |
Correct |
2 ms |
10576 KB |
answer = YES |
14 |
Correct |
2 ms |
10576 KB |
answer = YES |
15 |
Correct |
2 ms |
10576 KB |
answer = YES |
16 |
Correct |
2 ms |
10576 KB |
answer = YES |
17 |
Correct |
2 ms |
8528 KB |
answer = YES |
18 |
Correct |
2 ms |
10576 KB |
answer = YES |
19 |
Correct |
2 ms |
10576 KB |
answer = YES |
20 |
Correct |
2 ms |
10576 KB |
answer = YES |
21 |
Correct |
2 ms |
10740 KB |
answer = YES |
22 |
Correct |
2 ms |
10576 KB |
answer = NO |
23 |
Correct |
2 ms |
10576 KB |
answer = NO |
24 |
Correct |
2 ms |
10576 KB |
answer = YES |
25 |
Correct |
2 ms |
10588 KB |
answer = YES |
26 |
Correct |
2 ms |
10576 KB |
answer = YES |
27 |
Correct |
2 ms |
10748 KB |
answer = YES |
28 |
Correct |
2 ms |
10576 KB |
answer = YES |
29 |
Correct |
3 ms |
10576 KB |
answer = YES |
30 |
Correct |
2 ms |
10576 KB |
answer = NO |
31 |
Correct |
2 ms |
10576 KB |
answer = YES |
32 |
Correct |
2 ms |
10744 KB |
answer = YES |
33 |
Correct |
2 ms |
10576 KB |
answer = YES |
34 |
Correct |
2 ms |
10576 KB |
answer = YES |
35 |
Correct |
2 ms |
10576 KB |
answer = YES |
36 |
Correct |
2 ms |
10676 KB |
answer = YES |
37 |
Correct |
3 ms |
10576 KB |
answer = YES |
38 |
Correct |
2 ms |
10576 KB |
answer = YES |
39 |
Correct |
3 ms |
10576 KB |
answer = YES |
40 |
Correct |
3 ms |
10832 KB |
answer = YES |
41 |
Correct |
3 ms |
10832 KB |
answer = NO |
42 |
Correct |
3 ms |
10832 KB |
answer = YES |
43 |
Correct |
4 ms |
10832 KB |
answer = YES |
44 |
Correct |
4 ms |
10832 KB |
answer = YES |
45 |
Correct |
4 ms |
10888 KB |
answer = YES |
46 |
Correct |
3 ms |
10576 KB |
answer = YES |
47 |
Correct |
3 ms |
10832 KB |
answer = YES |
48 |
Correct |
3 ms |
10832 KB |
answer = YES |
49 |
Correct |
20 ms |
12092 KB |
answer = YES |
50 |
Correct |
9 ms |
12656 KB |
answer = YES |
51 |
Correct |
22 ms |
12492 KB |
answer = YES |
52 |
Correct |
7 ms |
12492 KB |
answer = NO |
53 |
Correct |
4 ms |
10832 KB |
answer = YES |
54 |
Correct |
5 ms |
11100 KB |
answer = YES |
55 |
Correct |
9 ms |
11344 KB |
answer = YES |
56 |
Correct |
20 ms |
12020 KB |
answer = YES |
57 |
Correct |
18 ms |
11600 KB |
answer = YES |
58 |
Correct |
15 ms |
11600 KB |
answer = YES |
59 |
Correct |
8 ms |
11980 KB |
answer = YES |
60 |
Correct |
17 ms |
11792 KB |
answer = YES |
61 |
Correct |
5 ms |
11344 KB |
answer = YES |
62 |
Correct |
51 ms |
21276 KB |
answer = NO |
63 |
Correct |
57 ms |
21256 KB |
answer = YES |
64 |
Correct |
62 ms |
21260 KB |
answer = NO |
65 |
Correct |
54 ms |
21256 KB |
answer = YES |
66 |
Correct |
5 ms |
10832 KB |
answer = YES |
67 |
Correct |
169 ms |
34736 KB |
answer = YES |
68 |
Correct |
154 ms |
34844 KB |
answer = YES |
69 |
Correct |
75 ms |
34740 KB |
answer = YES |
70 |
Correct |
93 ms |
40952 KB |
answer = YES |
71 |
Correct |
66 ms |
34996 KB |
answer = YES |
72 |
Correct |
153 ms |
23804 KB |
answer = YES |
73 |
Correct |
59 ms |
23812 KB |
answer = YES |
74 |
Correct |
45 ms |
21540 KB |
answer = YES |
75 |
Correct |
26 ms |
23504 KB |
answer = NO |
76 |
Correct |
20 ms |
11968 KB |
answer = YES |
77 |
Correct |
37 ms |
13256 KB |
answer = YES |
78 |
Correct |
66 ms |
16580 KB |
answer = YES |
79 |
Correct |
125 ms |
22780 KB |
answer = YES |
80 |
Correct |
102 ms |
23540 KB |
answer = YES |
81 |
Correct |
37 ms |
28608 KB |
answer = NO |
82 |
Correct |
74 ms |
33972 KB |
answer = YES |
83 |
Correct |
111 ms |
35504 KB |
answer = YES |
84 |
Correct |
174 ms |
35456 KB |
answer = YES |
85 |
Correct |
161 ms |
36276 KB |
answer = YES |
86 |
Correct |
75 ms |
36284 KB |
answer = YES |
87 |
Correct |
48 ms |
23232 KB |
answer = NO |
88 |
Correct |
108 ms |
27660 KB |
answer = YES |
89 |
Correct |
74 ms |
24600 KB |
answer = YES |
90 |
Correct |
68 ms |
21520 KB |
answer = YES |
91 |
Correct |
75 ms |
22212 KB |
answer = YES |
92 |
Correct |
35 ms |
17608 KB |
answer = YES |
93 |
Correct |
34 ms |
17608 KB |
answer = YES |
94 |
Correct |
71 ms |
36468 KB |
answer = NO |
95 |
Correct |
34 ms |
18632 KB |
answer = NO |
96 |
Correct |
155 ms |
38888 KB |
answer = YES |
97 |
Correct |
46 ms |
35772 KB |
answer = NO |