Submission #254790

# Submission time Handle Problem Language Result Execution time Memory
254790 2020-07-30T15:25:24 Z model_code Graph (BOI20_graph) C++11
100 / 100
199 ms 14200 KB
#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

const int MAXN = 200005;

int n, m;
vector<pii> g[MAXN];

int vis[MAXN];
int sgn[MAXN];
int val[MAXN];

queue<int> Q;

int ans[MAXN];

int cnt;
int comp[MAXN];
int num[MAXN];

void solve() {
	memset(vis,0,sizeof(vis));
	for(int u = 1; u <= n; u++) {
		if(!vis[u]) {
			vis[u] = true;
			sgn[u] = +1;
			val[u] = 0;
			cnt = 0;
			comp[cnt++] = u;
			bool bip = true;
			double x;
			Q.push(u);
			while(!Q.empty()) {
				int v = Q.front(); Q.pop();
				for(size_t i = 0; i < g[v].size(); i++) {
					int w = g[v][i].fst;
					int sum = g[v][i].snd;
					if(!vis[w]) {
						vis[w] = true;
						sgn[w] = -sgn[v];
						val[w] = sum-val[v];
						comp[cnt++] = w;
						Q.push(w);
					} else if(sgn[w]==sgn[v]) {
						bip = false;
						x = sgn[w]*(sum-val[w]-val[v])/2;
					}
				}
			}
			
			if(bip) {
				for(int i = 0; i < cnt; i++) {
					int v = comp[i];
					num[i] = (-sgn[v])*val[v];
				}
				sort(num,num+cnt);
				x = num[cnt/2];
			}
			
			for(int i = 0; i < cnt; i++) {
				int v = comp[i];
				ans[v] = val[v] + sgn[v]*x;
			}
			
			for(int i = 0; i < cnt; i++) {
				int v = comp[i];
				for(size_t i = 0; i < g[v].size(); i++) {
					int w = g[v][i].fst;
					if(ans[v]+ans[w]!=g[v][i].snd) {
						printf("NO\n");
						return;
					}
				}
			}
		}
	}
	
	printf("YES\n");
	for(int v = 1; v <= n; v++) {
		printf("%.1lf ", 0.5*ans[v]);
	}
	printf("\n");
}

int main() {
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	while(scanf("%d %d", &n, &m)==2) {
		for(int i = 1; i <= n; i++) {
			g[i].clear();
		}
		for(int i = 0; i < m; i++) {
			int a, b, c; scanf("%d %d %d", &a, &b, &c);
			c *= 2;
			g[a].pb(mp(b,c));
			g[b].pb(mp(a,c));
		}
		solve();
	}
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:128:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int a, b, c; scanf("%d %d %d", &a, &b, &c);
                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB answer = YES
2 Correct 3 ms 5760 KB answer = YES
3 Correct 3 ms 5760 KB answer = YES
4 Correct 3 ms 5760 KB answer = NO
5 Correct 3 ms 5760 KB answer = YES
6 Correct 3 ms 5760 KB answer = YES
7 Correct 4 ms 5760 KB answer = YES
8 Correct 3 ms 5760 KB answer = YES
9 Correct 3 ms 5760 KB answer = NO
10 Correct 5 ms 5760 KB answer = YES
11 Correct 3 ms 5760 KB answer = YES
12 Correct 4 ms 5760 KB answer = NO
13 Correct 5 ms 5760 KB answer = YES
14 Correct 3 ms 5760 KB answer = YES
15 Correct 3 ms 5760 KB answer = YES
16 Correct 4 ms 5760 KB answer = YES
17 Correct 4 ms 5760 KB answer = YES
18 Correct 3 ms 5760 KB answer = YES
19 Correct 3 ms 5760 KB answer = YES
20 Correct 3 ms 5760 KB answer = YES
21 Correct 4 ms 5760 KB answer = YES
22 Correct 4 ms 5760 KB answer = NO
23 Correct 4 ms 5760 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB answer = YES
2 Correct 3 ms 5760 KB answer = YES
3 Correct 3 ms 5760 KB answer = YES
4 Correct 3 ms 5760 KB answer = NO
5 Correct 3 ms 5760 KB answer = YES
6 Correct 3 ms 5760 KB answer = YES
7 Correct 4 ms 5760 KB answer = YES
8 Correct 3 ms 5760 KB answer = YES
9 Correct 3 ms 5760 KB answer = NO
10 Correct 5 ms 5760 KB answer = YES
11 Correct 3 ms 5760 KB answer = YES
12 Correct 4 ms 5760 KB answer = NO
13 Correct 5 ms 5760 KB answer = YES
14 Correct 3 ms 5760 KB answer = YES
15 Correct 3 ms 5760 KB answer = YES
16 Correct 4 ms 5760 KB answer = YES
17 Correct 4 ms 5760 KB answer = YES
18 Correct 3 ms 5760 KB answer = YES
19 Correct 3 ms 5760 KB answer = YES
20 Correct 3 ms 5760 KB answer = YES
21 Correct 4 ms 5760 KB answer = YES
22 Correct 4 ms 5760 KB answer = NO
23 Correct 4 ms 5760 KB answer = NO
24 Correct 3 ms 5760 KB answer = YES
25 Correct 4 ms 5760 KB answer = YES
26 Correct 4 ms 5760 KB answer = YES
27 Correct 4 ms 5888 KB answer = YES
28 Correct 4 ms 5888 KB answer = YES
29 Correct 6 ms 5760 KB answer = YES
30 Correct 4 ms 5760 KB answer = NO
31 Correct 4 ms 5760 KB answer = YES
32 Correct 4 ms 5760 KB answer = YES
33 Correct 3 ms 5760 KB answer = YES
34 Correct 4 ms 5760 KB answer = YES
35 Correct 4 ms 5760 KB answer = YES
36 Correct 4 ms 5760 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB answer = YES
2 Correct 3 ms 5760 KB answer = YES
3 Correct 3 ms 5760 KB answer = YES
4 Correct 3 ms 5760 KB answer = NO
5 Correct 3 ms 5760 KB answer = YES
6 Correct 3 ms 5760 KB answer = YES
7 Correct 4 ms 5760 KB answer = YES
8 Correct 3 ms 5760 KB answer = YES
9 Correct 3 ms 5760 KB answer = NO
10 Correct 5 ms 5760 KB answer = YES
11 Correct 3 ms 5760 KB answer = YES
12 Correct 4 ms 5760 KB answer = NO
13 Correct 5 ms 5760 KB answer = YES
14 Correct 3 ms 5760 KB answer = YES
15 Correct 3 ms 5760 KB answer = YES
16 Correct 4 ms 5760 KB answer = YES
17 Correct 4 ms 5760 KB answer = YES
18 Correct 3 ms 5760 KB answer = YES
19 Correct 3 ms 5760 KB answer = YES
20 Correct 3 ms 5760 KB answer = YES
21 Correct 4 ms 5760 KB answer = YES
22 Correct 4 ms 5760 KB answer = NO
23 Correct 4 ms 5760 KB answer = NO
24 Correct 3 ms 5760 KB answer = YES
25 Correct 4 ms 5760 KB answer = YES
26 Correct 4 ms 5760 KB answer = YES
27 Correct 4 ms 5888 KB answer = YES
28 Correct 4 ms 5888 KB answer = YES
29 Correct 6 ms 5760 KB answer = YES
30 Correct 4 ms 5760 KB answer = NO
31 Correct 4 ms 5760 KB answer = YES
32 Correct 4 ms 5760 KB answer = YES
33 Correct 3 ms 5760 KB answer = YES
34 Correct 4 ms 5760 KB answer = YES
35 Correct 4 ms 5760 KB answer = YES
36 Correct 4 ms 5760 KB answer = YES
37 Correct 3 ms 5888 KB answer = YES
38 Correct 5 ms 5888 KB answer = YES
39 Correct 6 ms 5888 KB answer = YES
40 Correct 5 ms 5888 KB answer = YES
41 Correct 6 ms 5888 KB answer = NO
42 Correct 5 ms 5888 KB answer = YES
43 Correct 4 ms 5888 KB answer = YES
44 Correct 5 ms 5888 KB answer = YES
45 Correct 4 ms 5888 KB answer = YES
46 Correct 5 ms 5888 KB answer = YES
47 Correct 5 ms 5888 KB answer = YES
48 Correct 6 ms 5888 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB answer = YES
2 Correct 3 ms 5760 KB answer = YES
3 Correct 3 ms 5760 KB answer = YES
4 Correct 3 ms 5760 KB answer = NO
5 Correct 3 ms 5760 KB answer = YES
6 Correct 3 ms 5760 KB answer = YES
7 Correct 4 ms 5760 KB answer = YES
8 Correct 3 ms 5760 KB answer = YES
9 Correct 3 ms 5760 KB answer = NO
10 Correct 5 ms 5760 KB answer = YES
11 Correct 3 ms 5760 KB answer = YES
12 Correct 4 ms 5760 KB answer = NO
13 Correct 5 ms 5760 KB answer = YES
14 Correct 3 ms 5760 KB answer = YES
15 Correct 3 ms 5760 KB answer = YES
16 Correct 4 ms 5760 KB answer = YES
17 Correct 4 ms 5760 KB answer = YES
18 Correct 3 ms 5760 KB answer = YES
19 Correct 3 ms 5760 KB answer = YES
20 Correct 3 ms 5760 KB answer = YES
21 Correct 4 ms 5760 KB answer = YES
22 Correct 4 ms 5760 KB answer = NO
23 Correct 4 ms 5760 KB answer = NO
24 Correct 3 ms 5760 KB answer = YES
25 Correct 4 ms 5760 KB answer = YES
26 Correct 4 ms 5760 KB answer = YES
27 Correct 4 ms 5888 KB answer = YES
28 Correct 4 ms 5888 KB answer = YES
29 Correct 6 ms 5760 KB answer = YES
30 Correct 4 ms 5760 KB answer = NO
31 Correct 4 ms 5760 KB answer = YES
32 Correct 4 ms 5760 KB answer = YES
33 Correct 3 ms 5760 KB answer = YES
34 Correct 4 ms 5760 KB answer = YES
35 Correct 4 ms 5760 KB answer = YES
36 Correct 4 ms 5760 KB answer = YES
37 Correct 3 ms 5888 KB answer = YES
38 Correct 5 ms 5888 KB answer = YES
39 Correct 6 ms 5888 KB answer = YES
40 Correct 5 ms 5888 KB answer = YES
41 Correct 6 ms 5888 KB answer = NO
42 Correct 5 ms 5888 KB answer = YES
43 Correct 4 ms 5888 KB answer = YES
44 Correct 5 ms 5888 KB answer = YES
45 Correct 4 ms 5888 KB answer = YES
46 Correct 5 ms 5888 KB answer = YES
47 Correct 5 ms 5888 KB answer = YES
48 Correct 6 ms 5888 KB answer = YES
49 Correct 11 ms 6400 KB answer = YES
50 Correct 11 ms 6272 KB answer = YES
51 Correct 11 ms 6400 KB answer = YES
52 Correct 9 ms 6272 KB answer = NO
53 Correct 4 ms 5888 KB answer = YES
54 Correct 5 ms 6016 KB answer = YES
55 Correct 7 ms 6144 KB answer = YES
56 Correct 10 ms 6400 KB answer = YES
57 Correct 10 ms 6400 KB answer = YES
58 Correct 12 ms 6272 KB answer = YES
59 Correct 11 ms 6272 KB answer = YES
60 Correct 11 ms 6400 KB answer = YES
61 Correct 7 ms 6144 KB answer = YES
62 Correct 86 ms 10616 KB answer = NO
63 Correct 86 ms 10616 KB answer = YES
64 Correct 89 ms 10616 KB answer = NO
65 Correct 92 ms 10616 KB answer = YES
66 Correct 6 ms 5888 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB answer = YES
2 Correct 3 ms 5760 KB answer = YES
3 Correct 3 ms 5760 KB answer = YES
4 Correct 3 ms 5760 KB answer = NO
5 Correct 3 ms 5760 KB answer = YES
6 Correct 3 ms 5760 KB answer = YES
7 Correct 4 ms 5760 KB answer = YES
8 Correct 3 ms 5760 KB answer = YES
9 Correct 3 ms 5760 KB answer = NO
10 Correct 5 ms 5760 KB answer = YES
11 Correct 3 ms 5760 KB answer = YES
12 Correct 4 ms 5760 KB answer = NO
13 Correct 5 ms 5760 KB answer = YES
14 Correct 3 ms 5760 KB answer = YES
15 Correct 3 ms 5760 KB answer = YES
16 Correct 4 ms 5760 KB answer = YES
17 Correct 4 ms 5760 KB answer = YES
18 Correct 3 ms 5760 KB answer = YES
19 Correct 3 ms 5760 KB answer = YES
20 Correct 3 ms 5760 KB answer = YES
21 Correct 4 ms 5760 KB answer = YES
22 Correct 4 ms 5760 KB answer = NO
23 Correct 4 ms 5760 KB answer = NO
24 Correct 3 ms 5760 KB answer = YES
25 Correct 4 ms 5760 KB answer = YES
26 Correct 4 ms 5760 KB answer = YES
27 Correct 4 ms 5888 KB answer = YES
28 Correct 4 ms 5888 KB answer = YES
29 Correct 6 ms 5760 KB answer = YES
30 Correct 4 ms 5760 KB answer = NO
31 Correct 4 ms 5760 KB answer = YES
32 Correct 4 ms 5760 KB answer = YES
33 Correct 3 ms 5760 KB answer = YES
34 Correct 4 ms 5760 KB answer = YES
35 Correct 4 ms 5760 KB answer = YES
36 Correct 4 ms 5760 KB answer = YES
37 Correct 3 ms 5888 KB answer = YES
38 Correct 5 ms 5888 KB answer = YES
39 Correct 6 ms 5888 KB answer = YES
40 Correct 5 ms 5888 KB answer = YES
41 Correct 6 ms 5888 KB answer = NO
42 Correct 5 ms 5888 KB answer = YES
43 Correct 4 ms 5888 KB answer = YES
44 Correct 5 ms 5888 KB answer = YES
45 Correct 4 ms 5888 KB answer = YES
46 Correct 5 ms 5888 KB answer = YES
47 Correct 5 ms 5888 KB answer = YES
48 Correct 6 ms 5888 KB answer = YES
49 Correct 11 ms 6400 KB answer = YES
50 Correct 11 ms 6272 KB answer = YES
51 Correct 11 ms 6400 KB answer = YES
52 Correct 9 ms 6272 KB answer = NO
53 Correct 4 ms 5888 KB answer = YES
54 Correct 5 ms 6016 KB answer = YES
55 Correct 7 ms 6144 KB answer = YES
56 Correct 10 ms 6400 KB answer = YES
57 Correct 10 ms 6400 KB answer = YES
58 Correct 12 ms 6272 KB answer = YES
59 Correct 11 ms 6272 KB answer = YES
60 Correct 11 ms 6400 KB answer = YES
61 Correct 7 ms 6144 KB answer = YES
62 Correct 86 ms 10616 KB answer = NO
63 Correct 86 ms 10616 KB answer = YES
64 Correct 89 ms 10616 KB answer = NO
65 Correct 92 ms 10616 KB answer = YES
66 Correct 6 ms 5888 KB answer = YES
67 Correct 84 ms 11452 KB answer = YES
68 Correct 74 ms 11256 KB answer = YES
69 Correct 71 ms 10872 KB answer = YES
70 Correct 118 ms 14072 KB answer = YES
71 Correct 75 ms 10872 KB answer = YES
72 Correct 93 ms 12028 KB answer = YES
73 Correct 95 ms 11640 KB answer = YES
74 Correct 57 ms 9208 KB answer = YES
75 Correct 43 ms 9080 KB answer = NO
76 Correct 14 ms 6656 KB answer = YES
77 Correct 22 ms 7288 KB answer = YES
78 Correct 42 ms 8532 KB answer = YES
79 Correct 90 ms 11128 KB answer = YES
80 Correct 63 ms 9464 KB answer = YES
81 Correct 60 ms 10488 KB answer = NO
82 Correct 104 ms 11000 KB answer = YES
83 Correct 116 ms 11128 KB answer = YES
84 Correct 121 ms 11512 KB answer = YES
85 Correct 82 ms 11384 KB answer = YES
86 Correct 83 ms 11128 KB answer = YES
87 Correct 69 ms 10360 KB answer = NO
88 Correct 105 ms 10872 KB answer = YES
89 Correct 90 ms 10488 KB answer = YES
90 Correct 98 ms 10488 KB answer = YES
91 Correct 101 ms 10680 KB answer = YES
92 Correct 48 ms 8696 KB answer = YES
93 Correct 42 ms 8696 KB answer = YES
94 Correct 72 ms 10872 KB answer = NO
95 Correct 58 ms 10104 KB answer = NO
96 Correct 199 ms 14200 KB answer = YES
97 Correct 53 ms 11000 KB answer = NO