# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102007 |
2024-10-17T09:43:00 Z |
NDT134 |
Graph (BOI20_graph) |
C++14 |
|
700 ms |
9024 KB |
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
using pi = pair<int, int>;
int main() {
int n, M; cin >> n >> M;
vector<vector<pi>> g(n);
for (int i = 0; i < M; i++)
{
int x, y, z; cin >> x >> y >> z; x--; y--;
g[x].push_back({ y, z });
g[y].push_back({ x, z });
}
vector<pi> v(n, { -1 , 0 });
vector<double> r(n, 0.1);
bool b = 1;
for (int i = 0; i < n; i++)
{
if (!v[i].second)
{
double a = 0.1;
v[i] = { 0, 1 };
vector<pi> c(1,v[i]);
vector<int> aa(1, i);
queue<int> q; q.push(i);
while (!q.empty() && a == 0.1)
{
int x = q.front(); q.pop();
for (pi p : g[x])
{
int y = p.first;
if (!v[y].second)
{
v[y] = { -v[x].first + p.second,-v[x].second };
c.push_back(v[y]);
aa.push_back(y);
q.push(y);
}
else
{
if (v[y].second != v[x].second)
{
if (v[x].first + v[y].first != p.second)
{
cout << "NO" << endl;
return 0;
}
}
else
{
a = 0.5 * (v[y].first + v[x].first - p.second) * (-v[x].second);
break;
}
}
}
}
if (a != 0.1)
{
while (!q.empty())
{
q.pop();
}
q.push(i);
r[i] = a;
while (!q.empty())
{
int x = q.front(); q.pop();
for (pi p : g[x])
{
int y = p.first;
double rr = 1.0*p.second - r[x];
if (r[y] != 0.1 && r[y] != rr)
{
cout << "NO" << endl;
return 0;
}
if (r[y] == 0.1)
{
r[y] = rr;
q.push(y);
v[y] = { -2, -2 };
}
}
}
}
else
{
int x = 0;
for (pi p : c)
{
x += abs(p.first);
}
int mn = x, i = 0;
for (int m = -2*n; m <= 2*n; m++)
{
x = 0;
for (pi p : c)
{
x += abs(p.first + p.second * m);
}
if (x < mn)
{
mn = x;
i = m;
}
}
for (int x : aa)
{
pi p = v[x];
r[x] = p.first + p.second * i;
}
}
}
}
cout << "YES" << endl;
for (int i = 0; i < n; i++)
{
cout << r[i] << " ";
}
cout << endl;
return 0;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:21:7: warning: unused variable 'b' [-Wunused-variable]
21 | bool b = 1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
answer = YES |
2 |
Correct |
1 ms |
336 KB |
answer = YES |
3 |
Correct |
1 ms |
336 KB |
answer = YES |
4 |
Correct |
1 ms |
336 KB |
answer = NO |
5 |
Correct |
1 ms |
336 KB |
answer = YES |
6 |
Correct |
1 ms |
336 KB |
answer = YES |
7 |
Correct |
1 ms |
504 KB |
answer = YES |
8 |
Correct |
1 ms |
336 KB |
answer = YES |
9 |
Correct |
1 ms |
336 KB |
answer = NO |
10 |
Correct |
1 ms |
336 KB |
answer = YES |
11 |
Correct |
1 ms |
336 KB |
answer = YES |
12 |
Correct |
1 ms |
336 KB |
answer = NO |
13 |
Correct |
1 ms |
336 KB |
answer = YES |
14 |
Correct |
1 ms |
336 KB |
answer = YES |
15 |
Correct |
1 ms |
336 KB |
answer = YES |
16 |
Correct |
1 ms |
336 KB |
answer = YES |
17 |
Correct |
1 ms |
504 KB |
answer = YES |
18 |
Correct |
1 ms |
336 KB |
answer = YES |
19 |
Correct |
1 ms |
336 KB |
answer = YES |
20 |
Correct |
1 ms |
336 KB |
answer = YES |
21 |
Correct |
1 ms |
336 KB |
answer = YES |
22 |
Correct |
0 ms |
336 KB |
answer = NO |
23 |
Correct |
1 ms |
336 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
answer = YES |
2 |
Correct |
1 ms |
336 KB |
answer = YES |
3 |
Correct |
1 ms |
336 KB |
answer = YES |
4 |
Correct |
1 ms |
336 KB |
answer = NO |
5 |
Correct |
1 ms |
336 KB |
answer = YES |
6 |
Correct |
1 ms |
336 KB |
answer = YES |
7 |
Correct |
1 ms |
504 KB |
answer = YES |
8 |
Correct |
1 ms |
336 KB |
answer = YES |
9 |
Correct |
1 ms |
336 KB |
answer = NO |
10 |
Correct |
1 ms |
336 KB |
answer = YES |
11 |
Correct |
1 ms |
336 KB |
answer = YES |
12 |
Correct |
1 ms |
336 KB |
answer = NO |
13 |
Correct |
1 ms |
336 KB |
answer = YES |
14 |
Correct |
1 ms |
336 KB |
answer = YES |
15 |
Correct |
1 ms |
336 KB |
answer = YES |
16 |
Correct |
1 ms |
336 KB |
answer = YES |
17 |
Correct |
1 ms |
504 KB |
answer = YES |
18 |
Correct |
1 ms |
336 KB |
answer = YES |
19 |
Correct |
1 ms |
336 KB |
answer = YES |
20 |
Correct |
1 ms |
336 KB |
answer = YES |
21 |
Correct |
1 ms |
336 KB |
answer = YES |
22 |
Correct |
0 ms |
336 KB |
answer = NO |
23 |
Correct |
1 ms |
336 KB |
answer = NO |
24 |
Correct |
1 ms |
336 KB |
answer = YES |
25 |
Correct |
1 ms |
504 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
1 ms |
336 KB |
answer = YES |
28 |
Correct |
1 ms |
336 KB |
answer = YES |
29 |
Correct |
1 ms |
336 KB |
answer = YES |
30 |
Correct |
1 ms |
336 KB |
answer = NO |
31 |
Correct |
1 ms |
504 KB |
answer = YES |
32 |
Correct |
1 ms |
336 KB |
answer = YES |
33 |
Correct |
1 ms |
336 KB |
answer = YES |
34 |
Correct |
1 ms |
336 KB |
answer = YES |
35 |
Correct |
1 ms |
336 KB |
answer = YES |
36 |
Correct |
1 ms |
508 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
answer = YES |
2 |
Correct |
1 ms |
336 KB |
answer = YES |
3 |
Correct |
1 ms |
336 KB |
answer = YES |
4 |
Correct |
1 ms |
336 KB |
answer = NO |
5 |
Correct |
1 ms |
336 KB |
answer = YES |
6 |
Correct |
1 ms |
336 KB |
answer = YES |
7 |
Correct |
1 ms |
504 KB |
answer = YES |
8 |
Correct |
1 ms |
336 KB |
answer = YES |
9 |
Correct |
1 ms |
336 KB |
answer = NO |
10 |
Correct |
1 ms |
336 KB |
answer = YES |
11 |
Correct |
1 ms |
336 KB |
answer = YES |
12 |
Correct |
1 ms |
336 KB |
answer = NO |
13 |
Correct |
1 ms |
336 KB |
answer = YES |
14 |
Correct |
1 ms |
336 KB |
answer = YES |
15 |
Correct |
1 ms |
336 KB |
answer = YES |
16 |
Correct |
1 ms |
336 KB |
answer = YES |
17 |
Correct |
1 ms |
504 KB |
answer = YES |
18 |
Correct |
1 ms |
336 KB |
answer = YES |
19 |
Correct |
1 ms |
336 KB |
answer = YES |
20 |
Correct |
1 ms |
336 KB |
answer = YES |
21 |
Correct |
1 ms |
336 KB |
answer = YES |
22 |
Correct |
0 ms |
336 KB |
answer = NO |
23 |
Correct |
1 ms |
336 KB |
answer = NO |
24 |
Correct |
1 ms |
336 KB |
answer = YES |
25 |
Correct |
1 ms |
504 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
1 ms |
336 KB |
answer = YES |
28 |
Correct |
1 ms |
336 KB |
answer = YES |
29 |
Correct |
1 ms |
336 KB |
answer = YES |
30 |
Correct |
1 ms |
336 KB |
answer = NO |
31 |
Correct |
1 ms |
504 KB |
answer = YES |
32 |
Correct |
1 ms |
336 KB |
answer = YES |
33 |
Correct |
1 ms |
336 KB |
answer = YES |
34 |
Correct |
1 ms |
336 KB |
answer = YES |
35 |
Correct |
1 ms |
336 KB |
answer = YES |
36 |
Correct |
1 ms |
508 KB |
answer = YES |
37 |
Correct |
1 ms |
336 KB |
answer = YES |
38 |
Correct |
1 ms |
336 KB |
answer = YES |
39 |
Correct |
2 ms |
336 KB |
answer = YES |
40 |
Correct |
2 ms |
336 KB |
answer = YES |
41 |
Correct |
1 ms |
336 KB |
answer = NO |
42 |
Correct |
4 ms |
336 KB |
answer = YES |
43 |
Correct |
4 ms |
336 KB |
answer = YES |
44 |
Correct |
4 ms |
336 KB |
answer = YES |
45 |
Correct |
2 ms |
336 KB |
answer = YES |
46 |
Correct |
2 ms |
336 KB |
answer = YES |
47 |
Correct |
2 ms |
560 KB |
answer = YES |
48 |
Correct |
2 ms |
348 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
answer = YES |
2 |
Correct |
1 ms |
336 KB |
answer = YES |
3 |
Correct |
1 ms |
336 KB |
answer = YES |
4 |
Correct |
1 ms |
336 KB |
answer = NO |
5 |
Correct |
1 ms |
336 KB |
answer = YES |
6 |
Correct |
1 ms |
336 KB |
answer = YES |
7 |
Correct |
1 ms |
504 KB |
answer = YES |
8 |
Correct |
1 ms |
336 KB |
answer = YES |
9 |
Correct |
1 ms |
336 KB |
answer = NO |
10 |
Correct |
1 ms |
336 KB |
answer = YES |
11 |
Correct |
1 ms |
336 KB |
answer = YES |
12 |
Correct |
1 ms |
336 KB |
answer = NO |
13 |
Correct |
1 ms |
336 KB |
answer = YES |
14 |
Correct |
1 ms |
336 KB |
answer = YES |
15 |
Correct |
1 ms |
336 KB |
answer = YES |
16 |
Correct |
1 ms |
336 KB |
answer = YES |
17 |
Correct |
1 ms |
504 KB |
answer = YES |
18 |
Correct |
1 ms |
336 KB |
answer = YES |
19 |
Correct |
1 ms |
336 KB |
answer = YES |
20 |
Correct |
1 ms |
336 KB |
answer = YES |
21 |
Correct |
1 ms |
336 KB |
answer = YES |
22 |
Correct |
0 ms |
336 KB |
answer = NO |
23 |
Correct |
1 ms |
336 KB |
answer = NO |
24 |
Correct |
1 ms |
336 KB |
answer = YES |
25 |
Correct |
1 ms |
504 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
1 ms |
336 KB |
answer = YES |
28 |
Correct |
1 ms |
336 KB |
answer = YES |
29 |
Correct |
1 ms |
336 KB |
answer = YES |
30 |
Correct |
1 ms |
336 KB |
answer = NO |
31 |
Correct |
1 ms |
504 KB |
answer = YES |
32 |
Correct |
1 ms |
336 KB |
answer = YES |
33 |
Correct |
1 ms |
336 KB |
answer = YES |
34 |
Correct |
1 ms |
336 KB |
answer = YES |
35 |
Correct |
1 ms |
336 KB |
answer = YES |
36 |
Correct |
1 ms |
508 KB |
answer = YES |
37 |
Correct |
1 ms |
336 KB |
answer = YES |
38 |
Correct |
1 ms |
336 KB |
answer = YES |
39 |
Correct |
2 ms |
336 KB |
answer = YES |
40 |
Correct |
2 ms |
336 KB |
answer = YES |
41 |
Correct |
1 ms |
336 KB |
answer = NO |
42 |
Correct |
4 ms |
336 KB |
answer = YES |
43 |
Correct |
4 ms |
336 KB |
answer = YES |
44 |
Correct |
4 ms |
336 KB |
answer = YES |
45 |
Correct |
2 ms |
336 KB |
answer = YES |
46 |
Correct |
2 ms |
336 KB |
answer = YES |
47 |
Correct |
2 ms |
560 KB |
answer = YES |
48 |
Correct |
2 ms |
348 KB |
answer = YES |
49 |
Correct |
286 ms |
1360 KB |
answer = YES |
50 |
Correct |
9 ms |
1104 KB |
answer = YES |
51 |
Correct |
313 ms |
1268 KB |
answer = YES |
52 |
Correct |
6 ms |
1104 KB |
answer = NO |
53 |
Correct |
4 ms |
336 KB |
answer = YES |
54 |
Correct |
18 ms |
760 KB |
answer = YES |
55 |
Correct |
74 ms |
848 KB |
answer = YES |
56 |
Correct |
275 ms |
1360 KB |
answer = YES |
57 |
Correct |
330 ms |
1204 KB |
answer = YES |
58 |
Correct |
226 ms |
1132 KB |
answer = YES |
59 |
Correct |
8 ms |
1104 KB |
answer = YES |
60 |
Correct |
286 ms |
1104 KB |
answer = YES |
61 |
Correct |
4 ms |
848 KB |
answer = YES |
62 |
Correct |
82 ms |
5316 KB |
answer = NO |
63 |
Correct |
89 ms |
5196 KB |
answer = YES |
64 |
Correct |
82 ms |
5320 KB |
answer = NO |
65 |
Correct |
89 ms |
5192 KB |
answer = YES |
66 |
Correct |
13 ms |
764 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
answer = YES |
2 |
Correct |
1 ms |
336 KB |
answer = YES |
3 |
Correct |
1 ms |
336 KB |
answer = YES |
4 |
Correct |
1 ms |
336 KB |
answer = NO |
5 |
Correct |
1 ms |
336 KB |
answer = YES |
6 |
Correct |
1 ms |
336 KB |
answer = YES |
7 |
Correct |
1 ms |
504 KB |
answer = YES |
8 |
Correct |
1 ms |
336 KB |
answer = YES |
9 |
Correct |
1 ms |
336 KB |
answer = NO |
10 |
Correct |
1 ms |
336 KB |
answer = YES |
11 |
Correct |
1 ms |
336 KB |
answer = YES |
12 |
Correct |
1 ms |
336 KB |
answer = NO |
13 |
Correct |
1 ms |
336 KB |
answer = YES |
14 |
Correct |
1 ms |
336 KB |
answer = YES |
15 |
Correct |
1 ms |
336 KB |
answer = YES |
16 |
Correct |
1 ms |
336 KB |
answer = YES |
17 |
Correct |
1 ms |
504 KB |
answer = YES |
18 |
Correct |
1 ms |
336 KB |
answer = YES |
19 |
Correct |
1 ms |
336 KB |
answer = YES |
20 |
Correct |
1 ms |
336 KB |
answer = YES |
21 |
Correct |
1 ms |
336 KB |
answer = YES |
22 |
Correct |
0 ms |
336 KB |
answer = NO |
23 |
Correct |
1 ms |
336 KB |
answer = NO |
24 |
Correct |
1 ms |
336 KB |
answer = YES |
25 |
Correct |
1 ms |
504 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
1 ms |
336 KB |
answer = YES |
28 |
Correct |
1 ms |
336 KB |
answer = YES |
29 |
Correct |
1 ms |
336 KB |
answer = YES |
30 |
Correct |
1 ms |
336 KB |
answer = NO |
31 |
Correct |
1 ms |
504 KB |
answer = YES |
32 |
Correct |
1 ms |
336 KB |
answer = YES |
33 |
Correct |
1 ms |
336 KB |
answer = YES |
34 |
Correct |
1 ms |
336 KB |
answer = YES |
35 |
Correct |
1 ms |
336 KB |
answer = YES |
36 |
Correct |
1 ms |
508 KB |
answer = YES |
37 |
Correct |
1 ms |
336 KB |
answer = YES |
38 |
Correct |
1 ms |
336 KB |
answer = YES |
39 |
Correct |
2 ms |
336 KB |
answer = YES |
40 |
Correct |
2 ms |
336 KB |
answer = YES |
41 |
Correct |
1 ms |
336 KB |
answer = NO |
42 |
Correct |
4 ms |
336 KB |
answer = YES |
43 |
Correct |
4 ms |
336 KB |
answer = YES |
44 |
Correct |
4 ms |
336 KB |
answer = YES |
45 |
Correct |
2 ms |
336 KB |
answer = YES |
46 |
Correct |
2 ms |
336 KB |
answer = YES |
47 |
Correct |
2 ms |
560 KB |
answer = YES |
48 |
Correct |
2 ms |
348 KB |
answer = YES |
49 |
Correct |
286 ms |
1360 KB |
answer = YES |
50 |
Correct |
9 ms |
1104 KB |
answer = YES |
51 |
Correct |
313 ms |
1268 KB |
answer = YES |
52 |
Correct |
6 ms |
1104 KB |
answer = NO |
53 |
Correct |
4 ms |
336 KB |
answer = YES |
54 |
Correct |
18 ms |
760 KB |
answer = YES |
55 |
Correct |
74 ms |
848 KB |
answer = YES |
56 |
Correct |
275 ms |
1360 KB |
answer = YES |
57 |
Correct |
330 ms |
1204 KB |
answer = YES |
58 |
Correct |
226 ms |
1132 KB |
answer = YES |
59 |
Correct |
8 ms |
1104 KB |
answer = YES |
60 |
Correct |
286 ms |
1104 KB |
answer = YES |
61 |
Correct |
4 ms |
848 KB |
answer = YES |
62 |
Correct |
82 ms |
5316 KB |
answer = NO |
63 |
Correct |
89 ms |
5196 KB |
answer = YES |
64 |
Correct |
82 ms |
5320 KB |
answer = NO |
65 |
Correct |
89 ms |
5192 KB |
answer = YES |
66 |
Correct |
13 ms |
764 KB |
answer = YES |
67 |
Execution timed out |
1032 ms |
9024 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |