Submission #258912

# Submission time Handle Problem Language Result Execution time Memory
258912 2020-08-06T17:53:03 Z easrui Graph (BOI20_graph) C++14
100 / 100
244 ms 26348 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const int MN = 2e5+5;

//start at 1:43

int E[MN],dep[MN],cnt[MN],par[MN],odd[MN],cur;
double C[MN],sum[MN],val[MN];
vector<int> G[MN],group;
vector<double> tmp;
bool vis[MN],fail;

void dfs(int s)
{
	vis[s] = 1;
	for(int d:G[s]){
		int e = E[d]-s;
		if(vis[e]){
			if(dep[e]<dep[s]) continue;
			if((dep[e]-dep[s])%2){
				if( (cnt[e]-cnt[par[s]]) - (cnt[par[e]]-cnt[s]) != C[d]-1) fail = 1;
			}
			else{
				if(odd[cur]) continue;
				odd[cur] = s;
				val[s] = (-sum[e]+sum[s]+sum[par[e]]-sum[par[s]]+C[d])/2.0;
			}
		}
		else{
			par[e] = s;
			dep[e] = dep[s]+1;
			cnt[e] = cnt[par[s]];
			if(C[d]==2) cnt[e]++;
			sum[e] = sum[par[s]]+C[d];
			dfs(e);
		}
	}
}

void solve(int s)
{
	group.push_back(s);
	vis[s] = 1;
	for(int d:G[s]){
		int e = E[d]-s;
		if(vis[e]){
			if(odd[cur]&&val[s]+val[e]!=C[d]) fail = 1;
		}
		else{
			val[e] = C[d]-val[s];
			solve(e);
		}
	}
	tmp.push_back(dep[s]%2 ? -val[s] : val[s]);
}

int N,M;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> N >> M;
    for(int i=0; i<M; i++){
    	int a,b;
    	cin >> a >> b >> C[i];
    	E[i] = a+b;
    	G[a].push_back(i);
    	G[b].push_back(i);
    }
    for(int i=1; i<=N; i++){
    	if(vis[i]) continue;
    	cur = i;
    	dfs(i);
    }
    fill(vis,vis+N+1,0);

    for(int i=1; i<=N; i++){
    	if(vis[i]) continue;
    	cur = i;
		group.clear();
		tmp.clear();
    	if(odd[i]) solve(odd[i]);
    	else{
    	    solve(i);
		    sort(all(tmp));
		    double x = -tmp[group.size()/2];
		    for(int s:group){
		    	if(dep[s]%2) val[s] -= x;
		    	else val[s] += x;
		    }
    	}
    }

    fixed(cout);
    cout.precision(1);
    if(fail) cout << "NO";
    else{
    	cout << "YES\n";
    	for(int i=1; i<=N; i++) cout << val[i] << ' ';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 4 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Correct 3 ms 5120 KB answer = YES
6 Correct 3 ms 5120 KB answer = YES
7 Correct 3 ms 5120 KB answer = YES
8 Correct 3 ms 5120 KB answer = YES
9 Correct 3 ms 5120 KB answer = NO
10 Correct 3 ms 5120 KB answer = YES
11 Correct 3 ms 5120 KB answer = YES
12 Correct 3 ms 5120 KB answer = NO
13 Correct 4 ms 5120 KB answer = YES
14 Correct 3 ms 5120 KB answer = YES
15 Correct 3 ms 5120 KB answer = YES
16 Correct 3 ms 5120 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 5120 KB answer = YES
19 Correct 3 ms 5120 KB answer = YES
20 Correct 3 ms 5120 KB answer = YES
21 Correct 3 ms 5024 KB answer = YES
22 Correct 3 ms 5120 KB answer = NO
23 Correct 3 ms 5120 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 4 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Correct 3 ms 5120 KB answer = YES
6 Correct 3 ms 5120 KB answer = YES
7 Correct 3 ms 5120 KB answer = YES
8 Correct 3 ms 5120 KB answer = YES
9 Correct 3 ms 5120 KB answer = NO
10 Correct 3 ms 5120 KB answer = YES
11 Correct 3 ms 5120 KB answer = YES
12 Correct 3 ms 5120 KB answer = NO
13 Correct 4 ms 5120 KB answer = YES
14 Correct 3 ms 5120 KB answer = YES
15 Correct 3 ms 5120 KB answer = YES
16 Correct 3 ms 5120 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 5120 KB answer = YES
19 Correct 3 ms 5120 KB answer = YES
20 Correct 3 ms 5120 KB answer = YES
21 Correct 3 ms 5024 KB answer = YES
22 Correct 3 ms 5120 KB answer = NO
23 Correct 3 ms 5120 KB answer = NO
24 Correct 3 ms 5120 KB answer = YES
25 Correct 3 ms 5120 KB answer = YES
26 Correct 3 ms 5120 KB answer = YES
27 Correct 3 ms 5120 KB answer = YES
28 Correct 3 ms 5120 KB answer = YES
29 Correct 3 ms 5120 KB answer = YES
30 Correct 3 ms 5120 KB answer = NO
31 Correct 3 ms 5120 KB answer = YES
32 Correct 3 ms 5120 KB answer = YES
33 Correct 3 ms 5120 KB answer = YES
34 Correct 3 ms 5120 KB answer = YES
35 Correct 3 ms 5120 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 4 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Correct 3 ms 5120 KB answer = YES
6 Correct 3 ms 5120 KB answer = YES
7 Correct 3 ms 5120 KB answer = YES
8 Correct 3 ms 5120 KB answer = YES
9 Correct 3 ms 5120 KB answer = NO
10 Correct 3 ms 5120 KB answer = YES
11 Correct 3 ms 5120 KB answer = YES
12 Correct 3 ms 5120 KB answer = NO
13 Correct 4 ms 5120 KB answer = YES
14 Correct 3 ms 5120 KB answer = YES
15 Correct 3 ms 5120 KB answer = YES
16 Correct 3 ms 5120 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 5120 KB answer = YES
19 Correct 3 ms 5120 KB answer = YES
20 Correct 3 ms 5120 KB answer = YES
21 Correct 3 ms 5024 KB answer = YES
22 Correct 3 ms 5120 KB answer = NO
23 Correct 3 ms 5120 KB answer = NO
24 Correct 3 ms 5120 KB answer = YES
25 Correct 3 ms 5120 KB answer = YES
26 Correct 3 ms 5120 KB answer = YES
27 Correct 3 ms 5120 KB answer = YES
28 Correct 3 ms 5120 KB answer = YES
29 Correct 3 ms 5120 KB answer = YES
30 Correct 3 ms 5120 KB answer = NO
31 Correct 3 ms 5120 KB answer = YES
32 Correct 3 ms 5120 KB answer = YES
33 Correct 3 ms 5120 KB answer = YES
34 Correct 3 ms 5120 KB answer = YES
35 Correct 3 ms 5120 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
37 Correct 3 ms 5120 KB answer = YES
38 Correct 3 ms 5120 KB answer = YES
39 Correct 4 ms 5120 KB answer = YES
40 Correct 4 ms 5248 KB answer = YES
41 Correct 4 ms 5248 KB answer = NO
42 Correct 4 ms 5248 KB answer = YES
43 Correct 4 ms 5248 KB answer = YES
44 Correct 4 ms 5248 KB answer = YES
45 Correct 4 ms 5248 KB answer = YES
46 Correct 4 ms 5120 KB answer = YES
47 Correct 4 ms 5248 KB answer = YES
48 Correct 4 ms 5248 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 4 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Correct 3 ms 5120 KB answer = YES
6 Correct 3 ms 5120 KB answer = YES
7 Correct 3 ms 5120 KB answer = YES
8 Correct 3 ms 5120 KB answer = YES
9 Correct 3 ms 5120 KB answer = NO
10 Correct 3 ms 5120 KB answer = YES
11 Correct 3 ms 5120 KB answer = YES
12 Correct 3 ms 5120 KB answer = NO
13 Correct 4 ms 5120 KB answer = YES
14 Correct 3 ms 5120 KB answer = YES
15 Correct 3 ms 5120 KB answer = YES
16 Correct 3 ms 5120 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 5120 KB answer = YES
19 Correct 3 ms 5120 KB answer = YES
20 Correct 3 ms 5120 KB answer = YES
21 Correct 3 ms 5024 KB answer = YES
22 Correct 3 ms 5120 KB answer = NO
23 Correct 3 ms 5120 KB answer = NO
24 Correct 3 ms 5120 KB answer = YES
25 Correct 3 ms 5120 KB answer = YES
26 Correct 3 ms 5120 KB answer = YES
27 Correct 3 ms 5120 KB answer = YES
28 Correct 3 ms 5120 KB answer = YES
29 Correct 3 ms 5120 KB answer = YES
30 Correct 3 ms 5120 KB answer = NO
31 Correct 3 ms 5120 KB answer = YES
32 Correct 3 ms 5120 KB answer = YES
33 Correct 3 ms 5120 KB answer = YES
34 Correct 3 ms 5120 KB answer = YES
35 Correct 3 ms 5120 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
37 Correct 3 ms 5120 KB answer = YES
38 Correct 3 ms 5120 KB answer = YES
39 Correct 4 ms 5120 KB answer = YES
40 Correct 4 ms 5248 KB answer = YES
41 Correct 4 ms 5248 KB answer = NO
42 Correct 4 ms 5248 KB answer = YES
43 Correct 4 ms 5248 KB answer = YES
44 Correct 4 ms 5248 KB answer = YES
45 Correct 4 ms 5248 KB answer = YES
46 Correct 4 ms 5120 KB answer = YES
47 Correct 4 ms 5248 KB answer = YES
48 Correct 4 ms 5248 KB answer = YES
49 Correct 14 ms 6272 KB answer = YES
50 Correct 14 ms 6528 KB answer = YES
51 Correct 14 ms 6656 KB answer = YES
52 Correct 10 ms 6528 KB answer = NO
53 Correct 5 ms 5248 KB answer = YES
54 Correct 6 ms 5376 KB answer = YES
55 Correct 8 ms 5632 KB answer = YES
56 Correct 13 ms 6272 KB answer = YES
57 Correct 13 ms 6016 KB answer = YES
58 Correct 12 ms 6016 KB answer = YES
59 Correct 12 ms 6016 KB answer = YES
60 Correct 13 ms 6144 KB answer = YES
61 Correct 8 ms 5632 KB answer = YES
62 Correct 103 ms 13048 KB answer = NO
63 Correct 105 ms 13048 KB answer = YES
64 Correct 104 ms 12920 KB answer = NO
65 Correct 104 ms 13176 KB answer = YES
66 Correct 5 ms 5376 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB answer = YES
2 Correct 3 ms 5120 KB answer = YES
3 Correct 4 ms 5120 KB answer = YES
4 Correct 3 ms 5120 KB answer = NO
5 Correct 3 ms 5120 KB answer = YES
6 Correct 3 ms 5120 KB answer = YES
7 Correct 3 ms 5120 KB answer = YES
8 Correct 3 ms 5120 KB answer = YES
9 Correct 3 ms 5120 KB answer = NO
10 Correct 3 ms 5120 KB answer = YES
11 Correct 3 ms 5120 KB answer = YES
12 Correct 3 ms 5120 KB answer = NO
13 Correct 4 ms 5120 KB answer = YES
14 Correct 3 ms 5120 KB answer = YES
15 Correct 3 ms 5120 KB answer = YES
16 Correct 3 ms 5120 KB answer = YES
17 Correct 3 ms 4992 KB answer = YES
18 Correct 3 ms 5120 KB answer = YES
19 Correct 3 ms 5120 KB answer = YES
20 Correct 3 ms 5120 KB answer = YES
21 Correct 3 ms 5024 KB answer = YES
22 Correct 3 ms 5120 KB answer = NO
23 Correct 3 ms 5120 KB answer = NO
24 Correct 3 ms 5120 KB answer = YES
25 Correct 3 ms 5120 KB answer = YES
26 Correct 3 ms 5120 KB answer = YES
27 Correct 3 ms 5120 KB answer = YES
28 Correct 3 ms 5120 KB answer = YES
29 Correct 3 ms 5120 KB answer = YES
30 Correct 3 ms 5120 KB answer = NO
31 Correct 3 ms 5120 KB answer = YES
32 Correct 3 ms 5120 KB answer = YES
33 Correct 3 ms 5120 KB answer = YES
34 Correct 3 ms 5120 KB answer = YES
35 Correct 3 ms 5120 KB answer = YES
36 Correct 3 ms 5120 KB answer = YES
37 Correct 3 ms 5120 KB answer = YES
38 Correct 3 ms 5120 KB answer = YES
39 Correct 4 ms 5120 KB answer = YES
40 Correct 4 ms 5248 KB answer = YES
41 Correct 4 ms 5248 KB answer = NO
42 Correct 4 ms 5248 KB answer = YES
43 Correct 4 ms 5248 KB answer = YES
44 Correct 4 ms 5248 KB answer = YES
45 Correct 4 ms 5248 KB answer = YES
46 Correct 4 ms 5120 KB answer = YES
47 Correct 4 ms 5248 KB answer = YES
48 Correct 4 ms 5248 KB answer = YES
49 Correct 14 ms 6272 KB answer = YES
50 Correct 14 ms 6528 KB answer = YES
51 Correct 14 ms 6656 KB answer = YES
52 Correct 10 ms 6528 KB answer = NO
53 Correct 5 ms 5248 KB answer = YES
54 Correct 6 ms 5376 KB answer = YES
55 Correct 8 ms 5632 KB answer = YES
56 Correct 13 ms 6272 KB answer = YES
57 Correct 13 ms 6016 KB answer = YES
58 Correct 12 ms 6016 KB answer = YES
59 Correct 12 ms 6016 KB answer = YES
60 Correct 13 ms 6144 KB answer = YES
61 Correct 8 ms 5632 KB answer = YES
62 Correct 103 ms 13048 KB answer = NO
63 Correct 105 ms 13048 KB answer = YES
64 Correct 104 ms 12920 KB answer = NO
65 Correct 104 ms 13176 KB answer = YES
66 Correct 5 ms 5376 KB answer = YES
67 Correct 124 ms 21928 KB answer = YES
68 Correct 106 ms 21484 KB answer = YES
69 Correct 108 ms 21484 KB answer = YES
70 Correct 169 ms 26348 KB answer = YES
71 Correct 108 ms 21616 KB answer = YES
72 Correct 135 ms 15548 KB answer = YES
73 Correct 127 ms 15372 KB answer = YES
74 Correct 81 ms 14352 KB answer = YES
75 Correct 55 ms 14708 KB answer = NO
76 Correct 17 ms 6400 KB answer = YES
77 Correct 31 ms 7648 KB answer = YES
78 Correct 52 ms 9540 KB answer = YES
79 Correct 112 ms 13888 KB answer = YES
80 Correct 87 ms 15088 KB answer = YES
81 Correct 84 ms 18412 KB answer = NO
82 Correct 129 ms 19684 KB answer = YES
83 Correct 182 ms 21828 KB answer = YES
84 Correct 176 ms 21740 KB answer = YES
85 Correct 122 ms 21732 KB answer = YES
86 Correct 120 ms 21740 KB answer = YES
87 Correct 122 ms 16436 KB answer = NO
88 Correct 169 ms 17520 KB answer = YES
89 Correct 121 ms 14328 KB answer = YES
90 Correct 124 ms 14328 KB answer = YES
91 Correct 146 ms 14328 KB answer = YES
92 Correct 63 ms 10444 KB answer = YES
93 Correct 58 ms 10352 KB answer = YES
94 Correct 126 ms 21360 KB answer = NO
95 Correct 102 ms 13948 KB answer = NO
96 Correct 244 ms 22504 KB answer = YES
97 Correct 77 ms 21356 KB answer = NO