# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102249 |
2024-10-17T19:51:36 Z |
alexdd |
Graph (BOI20_graph) |
C++17 |
|
642 ms |
19604 KB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
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;
void dfs(int nod)
{
cur += abs(val[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;
}
}
vector<double> possible;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
for(double i = -40;i<=40;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++)
{
visited[i]=0;
}
double sum=0;
for(int i=1;i<=n;i++)
{
if(!visited[i])
{
double mnm=INF,unde;
for(double x:possible)
{
val[i] = x;
bun=1;
aux.clear();
cur=0;
dfs(i);
if(bun && cur<mnm)
{
mnm = cur;
unde = x;
}
for(int y:aux)
visited[y]=0;
}
if(mnm==INF)
{
cout<<"NO";
return 0;
}
val[i] = unde;
dfs(i);
sum += mnm;
}
}
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:72:20: warning: 'unde' may be used uninitialized in this function [-Wmaybe-uninitialized]
72 | val[i] = unde;
| ~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
answer = YES |
2 |
Correct |
1 ms |
4432 KB |
answer = YES |
3 |
Correct |
1 ms |
4432 KB |
answer = YES |
4 |
Correct |
1 ms |
4444 KB |
answer = NO |
5 |
Correct |
1 ms |
4432 KB |
answer = YES |
6 |
Correct |
1 ms |
4432 KB |
answer = YES |
7 |
Correct |
1 ms |
4432 KB |
answer = YES |
8 |
Correct |
1 ms |
4432 KB |
answer = YES |
9 |
Correct |
1 ms |
4432 KB |
answer = NO |
10 |
Correct |
1 ms |
4432 KB |
answer = YES |
11 |
Correct |
1 ms |
4432 KB |
answer = YES |
12 |
Correct |
2 ms |
4604 KB |
answer = NO |
13 |
Correct |
1 ms |
4432 KB |
answer = YES |
14 |
Correct |
1 ms |
4432 KB |
answer = YES |
15 |
Correct |
1 ms |
4432 KB |
answer = YES |
16 |
Correct |
1 ms |
4600 KB |
answer = YES |
17 |
Correct |
1 ms |
4432 KB |
answer = YES |
18 |
Correct |
1 ms |
4432 KB |
answer = YES |
19 |
Correct |
1 ms |
4600 KB |
answer = YES |
20 |
Correct |
1 ms |
4432 KB |
answer = YES |
21 |
Correct |
1 ms |
4432 KB |
answer = YES |
22 |
Correct |
1 ms |
4620 KB |
answer = NO |
23 |
Correct |
1 ms |
4432 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
answer = YES |
2 |
Correct |
1 ms |
4432 KB |
answer = YES |
3 |
Correct |
1 ms |
4432 KB |
answer = YES |
4 |
Correct |
1 ms |
4444 KB |
answer = NO |
5 |
Correct |
1 ms |
4432 KB |
answer = YES |
6 |
Correct |
1 ms |
4432 KB |
answer = YES |
7 |
Correct |
1 ms |
4432 KB |
answer = YES |
8 |
Correct |
1 ms |
4432 KB |
answer = YES |
9 |
Correct |
1 ms |
4432 KB |
answer = NO |
10 |
Correct |
1 ms |
4432 KB |
answer = YES |
11 |
Correct |
1 ms |
4432 KB |
answer = YES |
12 |
Correct |
2 ms |
4604 KB |
answer = NO |
13 |
Correct |
1 ms |
4432 KB |
answer = YES |
14 |
Correct |
1 ms |
4432 KB |
answer = YES |
15 |
Correct |
1 ms |
4432 KB |
answer = YES |
16 |
Correct |
1 ms |
4600 KB |
answer = YES |
17 |
Correct |
1 ms |
4432 KB |
answer = YES |
18 |
Correct |
1 ms |
4432 KB |
answer = YES |
19 |
Correct |
1 ms |
4600 KB |
answer = YES |
20 |
Correct |
1 ms |
4432 KB |
answer = YES |
21 |
Correct |
1 ms |
4432 KB |
answer = YES |
22 |
Correct |
1 ms |
4620 KB |
answer = NO |
23 |
Correct |
1 ms |
4432 KB |
answer = NO |
24 |
Correct |
1 ms |
4432 KB |
answer = YES |
25 |
Correct |
1 ms |
4432 KB |
answer = YES |
26 |
Correct |
1 ms |
4432 KB |
answer = YES |
27 |
Correct |
1 ms |
4432 KB |
answer = YES |
28 |
Correct |
1 ms |
4432 KB |
answer = YES |
29 |
Correct |
1 ms |
4432 KB |
answer = YES |
30 |
Correct |
1 ms |
4600 KB |
answer = NO |
31 |
Correct |
1 ms |
4432 KB |
answer = YES |
32 |
Correct |
1 ms |
4432 KB |
answer = YES |
33 |
Correct |
1 ms |
4432 KB |
answer = YES |
34 |
Correct |
1 ms |
4432 KB |
answer = YES |
35 |
Correct |
2 ms |
4432 KB |
answer = YES |
36 |
Correct |
2 ms |
4432 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
answer = YES |
2 |
Correct |
1 ms |
4432 KB |
answer = YES |
3 |
Correct |
1 ms |
4432 KB |
answer = YES |
4 |
Correct |
1 ms |
4444 KB |
answer = NO |
5 |
Correct |
1 ms |
4432 KB |
answer = YES |
6 |
Correct |
1 ms |
4432 KB |
answer = YES |
7 |
Correct |
1 ms |
4432 KB |
answer = YES |
8 |
Correct |
1 ms |
4432 KB |
answer = YES |
9 |
Correct |
1 ms |
4432 KB |
answer = NO |
10 |
Correct |
1 ms |
4432 KB |
answer = YES |
11 |
Correct |
1 ms |
4432 KB |
answer = YES |
12 |
Correct |
2 ms |
4604 KB |
answer = NO |
13 |
Correct |
1 ms |
4432 KB |
answer = YES |
14 |
Correct |
1 ms |
4432 KB |
answer = YES |
15 |
Correct |
1 ms |
4432 KB |
answer = YES |
16 |
Correct |
1 ms |
4600 KB |
answer = YES |
17 |
Correct |
1 ms |
4432 KB |
answer = YES |
18 |
Correct |
1 ms |
4432 KB |
answer = YES |
19 |
Correct |
1 ms |
4600 KB |
answer = YES |
20 |
Correct |
1 ms |
4432 KB |
answer = YES |
21 |
Correct |
1 ms |
4432 KB |
answer = YES |
22 |
Correct |
1 ms |
4620 KB |
answer = NO |
23 |
Correct |
1 ms |
4432 KB |
answer = NO |
24 |
Correct |
1 ms |
4432 KB |
answer = YES |
25 |
Correct |
1 ms |
4432 KB |
answer = YES |
26 |
Correct |
1 ms |
4432 KB |
answer = YES |
27 |
Correct |
1 ms |
4432 KB |
answer = YES |
28 |
Correct |
1 ms |
4432 KB |
answer = YES |
29 |
Correct |
1 ms |
4432 KB |
answer = YES |
30 |
Correct |
1 ms |
4600 KB |
answer = NO |
31 |
Correct |
1 ms |
4432 KB |
answer = YES |
32 |
Correct |
1 ms |
4432 KB |
answer = YES |
33 |
Correct |
1 ms |
4432 KB |
answer = YES |
34 |
Correct |
1 ms |
4432 KB |
answer = YES |
35 |
Correct |
2 ms |
4432 KB |
answer = YES |
36 |
Correct |
2 ms |
4432 KB |
answer = YES |
37 |
Correct |
2 ms |
4432 KB |
answer = YES |
38 |
Correct |
2 ms |
4432 KB |
answer = YES |
39 |
Correct |
2 ms |
4688 KB |
answer = YES |
40 |
Correct |
3 ms |
4688 KB |
answer = YES |
41 |
Correct |
3 ms |
4688 KB |
answer = NO |
42 |
Correct |
3 ms |
4688 KB |
answer = YES |
43 |
Correct |
3 ms |
4712 KB |
answer = YES |
44 |
Correct |
3 ms |
4856 KB |
answer = YES |
45 |
Correct |
3 ms |
4700 KB |
answer = YES |
46 |
Correct |
2 ms |
4688 KB |
answer = YES |
47 |
Correct |
4 ms |
4688 KB |
answer = YES |
48 |
Correct |
4 ms |
4688 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
answer = YES |
2 |
Correct |
1 ms |
4432 KB |
answer = YES |
3 |
Correct |
1 ms |
4432 KB |
answer = YES |
4 |
Correct |
1 ms |
4444 KB |
answer = NO |
5 |
Correct |
1 ms |
4432 KB |
answer = YES |
6 |
Correct |
1 ms |
4432 KB |
answer = YES |
7 |
Correct |
1 ms |
4432 KB |
answer = YES |
8 |
Correct |
1 ms |
4432 KB |
answer = YES |
9 |
Correct |
1 ms |
4432 KB |
answer = NO |
10 |
Correct |
1 ms |
4432 KB |
answer = YES |
11 |
Correct |
1 ms |
4432 KB |
answer = YES |
12 |
Correct |
2 ms |
4604 KB |
answer = NO |
13 |
Correct |
1 ms |
4432 KB |
answer = YES |
14 |
Correct |
1 ms |
4432 KB |
answer = YES |
15 |
Correct |
1 ms |
4432 KB |
answer = YES |
16 |
Correct |
1 ms |
4600 KB |
answer = YES |
17 |
Correct |
1 ms |
4432 KB |
answer = YES |
18 |
Correct |
1 ms |
4432 KB |
answer = YES |
19 |
Correct |
1 ms |
4600 KB |
answer = YES |
20 |
Correct |
1 ms |
4432 KB |
answer = YES |
21 |
Correct |
1 ms |
4432 KB |
answer = YES |
22 |
Correct |
1 ms |
4620 KB |
answer = NO |
23 |
Correct |
1 ms |
4432 KB |
answer = NO |
24 |
Correct |
1 ms |
4432 KB |
answer = YES |
25 |
Correct |
1 ms |
4432 KB |
answer = YES |
26 |
Correct |
1 ms |
4432 KB |
answer = YES |
27 |
Correct |
1 ms |
4432 KB |
answer = YES |
28 |
Correct |
1 ms |
4432 KB |
answer = YES |
29 |
Correct |
1 ms |
4432 KB |
answer = YES |
30 |
Correct |
1 ms |
4600 KB |
answer = NO |
31 |
Correct |
1 ms |
4432 KB |
answer = YES |
32 |
Correct |
1 ms |
4432 KB |
answer = YES |
33 |
Correct |
1 ms |
4432 KB |
answer = YES |
34 |
Correct |
1 ms |
4432 KB |
answer = YES |
35 |
Correct |
2 ms |
4432 KB |
answer = YES |
36 |
Correct |
2 ms |
4432 KB |
answer = YES |
37 |
Correct |
2 ms |
4432 KB |
answer = YES |
38 |
Correct |
2 ms |
4432 KB |
answer = YES |
39 |
Correct |
2 ms |
4688 KB |
answer = YES |
40 |
Correct |
3 ms |
4688 KB |
answer = YES |
41 |
Correct |
3 ms |
4688 KB |
answer = NO |
42 |
Correct |
3 ms |
4688 KB |
answer = YES |
43 |
Correct |
3 ms |
4712 KB |
answer = YES |
44 |
Correct |
3 ms |
4856 KB |
answer = YES |
45 |
Correct |
3 ms |
4700 KB |
answer = YES |
46 |
Correct |
2 ms |
4688 KB |
answer = YES |
47 |
Correct |
4 ms |
4688 KB |
answer = YES |
48 |
Correct |
4 ms |
4688 KB |
answer = YES |
49 |
Correct |
40 ms |
5236 KB |
answer = YES |
50 |
Correct |
35 ms |
5456 KB |
answer = YES |
51 |
Correct |
32 ms |
5456 KB |
answer = YES |
52 |
Correct |
29 ms |
5456 KB |
answer = NO |
53 |
Correct |
3 ms |
4688 KB |
answer = YES |
54 |
Correct |
6 ms |
4688 KB |
answer = YES |
55 |
Correct |
13 ms |
4944 KB |
answer = YES |
56 |
Correct |
36 ms |
5200 KB |
answer = YES |
57 |
Correct |
23 ms |
4944 KB |
answer = YES |
58 |
Correct |
23 ms |
5076 KB |
answer = YES |
59 |
Correct |
20 ms |
5200 KB |
answer = YES |
60 |
Correct |
30 ms |
5180 KB |
answer = YES |
61 |
Correct |
13 ms |
4944 KB |
answer = YES |
62 |
Correct |
217 ms |
10312 KB |
answer = NO |
63 |
Correct |
642 ms |
10312 KB |
answer = YES |
64 |
Correct |
629 ms |
10312 KB |
answer = NO |
65 |
Correct |
632 ms |
10444 KB |
answer = YES |
66 |
Correct |
5 ms |
4688 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
answer = YES |
2 |
Correct |
1 ms |
4432 KB |
answer = YES |
3 |
Correct |
1 ms |
4432 KB |
answer = YES |
4 |
Correct |
1 ms |
4444 KB |
answer = NO |
5 |
Correct |
1 ms |
4432 KB |
answer = YES |
6 |
Correct |
1 ms |
4432 KB |
answer = YES |
7 |
Correct |
1 ms |
4432 KB |
answer = YES |
8 |
Correct |
1 ms |
4432 KB |
answer = YES |
9 |
Correct |
1 ms |
4432 KB |
answer = NO |
10 |
Correct |
1 ms |
4432 KB |
answer = YES |
11 |
Correct |
1 ms |
4432 KB |
answer = YES |
12 |
Correct |
2 ms |
4604 KB |
answer = NO |
13 |
Correct |
1 ms |
4432 KB |
answer = YES |
14 |
Correct |
1 ms |
4432 KB |
answer = YES |
15 |
Correct |
1 ms |
4432 KB |
answer = YES |
16 |
Correct |
1 ms |
4600 KB |
answer = YES |
17 |
Correct |
1 ms |
4432 KB |
answer = YES |
18 |
Correct |
1 ms |
4432 KB |
answer = YES |
19 |
Correct |
1 ms |
4600 KB |
answer = YES |
20 |
Correct |
1 ms |
4432 KB |
answer = YES |
21 |
Correct |
1 ms |
4432 KB |
answer = YES |
22 |
Correct |
1 ms |
4620 KB |
answer = NO |
23 |
Correct |
1 ms |
4432 KB |
answer = NO |
24 |
Correct |
1 ms |
4432 KB |
answer = YES |
25 |
Correct |
1 ms |
4432 KB |
answer = YES |
26 |
Correct |
1 ms |
4432 KB |
answer = YES |
27 |
Correct |
1 ms |
4432 KB |
answer = YES |
28 |
Correct |
1 ms |
4432 KB |
answer = YES |
29 |
Correct |
1 ms |
4432 KB |
answer = YES |
30 |
Correct |
1 ms |
4600 KB |
answer = NO |
31 |
Correct |
1 ms |
4432 KB |
answer = YES |
32 |
Correct |
1 ms |
4432 KB |
answer = YES |
33 |
Correct |
1 ms |
4432 KB |
answer = YES |
34 |
Correct |
1 ms |
4432 KB |
answer = YES |
35 |
Correct |
2 ms |
4432 KB |
answer = YES |
36 |
Correct |
2 ms |
4432 KB |
answer = YES |
37 |
Correct |
2 ms |
4432 KB |
answer = YES |
38 |
Correct |
2 ms |
4432 KB |
answer = YES |
39 |
Correct |
2 ms |
4688 KB |
answer = YES |
40 |
Correct |
3 ms |
4688 KB |
answer = YES |
41 |
Correct |
3 ms |
4688 KB |
answer = NO |
42 |
Correct |
3 ms |
4688 KB |
answer = YES |
43 |
Correct |
3 ms |
4712 KB |
answer = YES |
44 |
Correct |
3 ms |
4856 KB |
answer = YES |
45 |
Correct |
3 ms |
4700 KB |
answer = YES |
46 |
Correct |
2 ms |
4688 KB |
answer = YES |
47 |
Correct |
4 ms |
4688 KB |
answer = YES |
48 |
Correct |
4 ms |
4688 KB |
answer = YES |
49 |
Correct |
40 ms |
5236 KB |
answer = YES |
50 |
Correct |
35 ms |
5456 KB |
answer = YES |
51 |
Correct |
32 ms |
5456 KB |
answer = YES |
52 |
Correct |
29 ms |
5456 KB |
answer = NO |
53 |
Correct |
3 ms |
4688 KB |
answer = YES |
54 |
Correct |
6 ms |
4688 KB |
answer = YES |
55 |
Correct |
13 ms |
4944 KB |
answer = YES |
56 |
Correct |
36 ms |
5200 KB |
answer = YES |
57 |
Correct |
23 ms |
4944 KB |
answer = YES |
58 |
Correct |
23 ms |
5076 KB |
answer = YES |
59 |
Correct |
20 ms |
5200 KB |
answer = YES |
60 |
Correct |
30 ms |
5180 KB |
answer = YES |
61 |
Correct |
13 ms |
4944 KB |
answer = YES |
62 |
Correct |
217 ms |
10312 KB |
answer = NO |
63 |
Correct |
642 ms |
10312 KB |
answer = YES |
64 |
Correct |
629 ms |
10312 KB |
answer = NO |
65 |
Correct |
632 ms |
10444 KB |
answer = YES |
66 |
Correct |
5 ms |
4688 KB |
answer = YES |
67 |
Correct |
223 ms |
16076 KB |
answer = YES |
68 |
Correct |
218 ms |
16064 KB |
answer = YES |
69 |
Correct |
223 ms |
16060 KB |
answer = YES |
70 |
Correct |
308 ms |
19604 KB |
answer = YES |
71 |
Correct |
227 ms |
16316 KB |
answer = YES |
72 |
Correct |
493 ms |
10432 KB |
answer = YES |
73 |
Correct |
520 ms |
10432 KB |
answer = YES |
74 |
Incorrect |
278 ms |
10700 KB |
jury has the better answer: jans = YES, pans = NO |
75 |
Halted |
0 ms |
0 KB |
- |