# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
580079 |
2022-06-20T14:33:52 Z |
jiahng |
Graph (BOI20_graph) |
C++14 |
|
68 ms |
10416 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 100010
#define INF (ll)1e9+10
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int N,M,a,b,c;
bool vis[maxn];
vpi adj[maxn];
ld value;
int status = 0; // status is 0 if not set, 1 if fixed and -1 if no solution
pi val[maxn];
vi v;
ld ans[maxn];
void dfs(int x){
if (status == -1) return;
vis[x] = 1;
v.pb(x);
aFOR(i,adj[x]){
if (vis[i.f]){
pi cur = val[x];
cur.f += val[i.f].f;
cur.s += val[i.f].s;
if (cur.f == 0){
if (cur.s != i.s){
status = -1; return;
}
}else{
ld newvalue = (ld(i.s) - ld(cur.s)) / ld(cur.f);
if (status == 1 && value != newvalue){
status = -1; return;
}
value = newvalue;
status = 1;
}
}else{
val[i.f] = pi(-val[x].f, i.s - val[x].s);
dfs(i.f);
}
}
}
int32_t main(){
fast;
cin >> N >> M;
FOR(i,1,M){
cin >> a >> b >> c;
adj[a].pb(pi(b, c)); adj[b].pb(pi(a,c));
}
FOR(i,1,N) if (!vis[i]){
val[i] = pi(1,0);
status = 0;
v.clear();
dfs(i);
if (status == -1){
cout << "NO"; return 0;
}else if (status == 0){
vi v2;
aFOR(j,v){
if (val[j].f == -1) v2.pb(val[j].s);
else v2.pb(-val[j].s);
}
sort(all(v2));
value = v2[v2.size()/2];
}
aFOR(j,v) ans[j] = (ld)val[j].f * value + (ld)val[j].s;
}
cout << "YES\n";
FOR(i,1,N) cout << ans[i] << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2612 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2692 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2692 KB |
answer = NO |
23 |
Correct |
3 ms |
2692 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2612 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2692 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2692 KB |
answer = NO |
23 |
Correct |
3 ms |
2692 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2688 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2692 KB |
answer = NO |
31 |
Correct |
2 ms |
2692 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
3 ms |
2644 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2612 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2692 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2692 KB |
answer = NO |
23 |
Correct |
3 ms |
2692 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2688 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2692 KB |
answer = NO |
31 |
Correct |
2 ms |
2692 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
3 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2720 KB |
answer = YES |
38 |
Correct |
2 ms |
2688 KB |
answer = YES |
39 |
Correct |
3 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2700 KB |
answer = YES |
41 |
Correct |
3 ms |
2644 KB |
answer = NO |
42 |
Correct |
3 ms |
2772 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Correct |
3 ms |
2704 KB |
answer = YES |
45 |
Correct |
3 ms |
2772 KB |
answer = YES |
46 |
Correct |
3 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2772 KB |
answer = YES |
48 |
Correct |
3 ms |
2772 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2612 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2692 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2692 KB |
answer = NO |
23 |
Correct |
3 ms |
2692 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2688 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2692 KB |
answer = NO |
31 |
Correct |
2 ms |
2692 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
3 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2720 KB |
answer = YES |
38 |
Correct |
2 ms |
2688 KB |
answer = YES |
39 |
Correct |
3 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2700 KB |
answer = YES |
41 |
Correct |
3 ms |
2644 KB |
answer = NO |
42 |
Correct |
3 ms |
2772 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Correct |
3 ms |
2704 KB |
answer = YES |
45 |
Correct |
3 ms |
2772 KB |
answer = YES |
46 |
Correct |
3 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2772 KB |
answer = YES |
48 |
Correct |
3 ms |
2772 KB |
answer = YES |
49 |
Correct |
11 ms |
3588 KB |
answer = YES |
50 |
Correct |
11 ms |
3904 KB |
answer = YES |
51 |
Correct |
11 ms |
3956 KB |
answer = YES |
52 |
Correct |
6 ms |
3152 KB |
answer = NO |
53 |
Correct |
3 ms |
2780 KB |
answer = YES |
54 |
Correct |
4 ms |
2900 KB |
answer = YES |
55 |
Correct |
6 ms |
3176 KB |
answer = YES |
56 |
Correct |
11 ms |
3656 KB |
answer = YES |
57 |
Correct |
14 ms |
3500 KB |
answer = YES |
58 |
Correct |
10 ms |
3412 KB |
answer = YES |
59 |
Correct |
11 ms |
3412 KB |
answer = YES |
60 |
Correct |
10 ms |
3540 KB |
answer = YES |
61 |
Correct |
7 ms |
3092 KB |
answer = YES |
62 |
Correct |
56 ms |
9932 KB |
answer = NO |
63 |
Correct |
68 ms |
10416 KB |
answer = YES |
64 |
Incorrect |
66 ms |
10368 KB |
Sum of endpoints for edge (7782; 2701) differs from the expected value 2. |
65 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2612 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
2 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2644 KB |
answer = YES |
14 |
Correct |
2 ms |
2692 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2688 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2692 KB |
answer = NO |
23 |
Correct |
3 ms |
2692 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2688 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
2 ms |
2692 KB |
answer = NO |
31 |
Correct |
2 ms |
2692 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
3 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2720 KB |
answer = YES |
38 |
Correct |
2 ms |
2688 KB |
answer = YES |
39 |
Correct |
3 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2700 KB |
answer = YES |
41 |
Correct |
3 ms |
2644 KB |
answer = NO |
42 |
Correct |
3 ms |
2772 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Correct |
3 ms |
2704 KB |
answer = YES |
45 |
Correct |
3 ms |
2772 KB |
answer = YES |
46 |
Correct |
3 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2772 KB |
answer = YES |
48 |
Correct |
3 ms |
2772 KB |
answer = YES |
49 |
Correct |
11 ms |
3588 KB |
answer = YES |
50 |
Correct |
11 ms |
3904 KB |
answer = YES |
51 |
Correct |
11 ms |
3956 KB |
answer = YES |
52 |
Correct |
6 ms |
3152 KB |
answer = NO |
53 |
Correct |
3 ms |
2780 KB |
answer = YES |
54 |
Correct |
4 ms |
2900 KB |
answer = YES |
55 |
Correct |
6 ms |
3176 KB |
answer = YES |
56 |
Correct |
11 ms |
3656 KB |
answer = YES |
57 |
Correct |
14 ms |
3500 KB |
answer = YES |
58 |
Correct |
10 ms |
3412 KB |
answer = YES |
59 |
Correct |
11 ms |
3412 KB |
answer = YES |
60 |
Correct |
10 ms |
3540 KB |
answer = YES |
61 |
Correct |
7 ms |
3092 KB |
answer = YES |
62 |
Correct |
56 ms |
9932 KB |
answer = NO |
63 |
Correct |
68 ms |
10416 KB |
answer = YES |
64 |
Incorrect |
66 ms |
10368 KB |
Sum of endpoints for edge (7782; 2701) differs from the expected value 2. |
65 |
Halted |
0 ms |
0 KB |
- |