Submission #272360

# Submission time Handle Problem Language Result Execution time Memory
272360 2020-08-18T11:32:33 Z arnold518 Graph (BOI20_graph) C++14
58 / 100
281 ms 15148 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, M;
vector<pii> adj[MAXN+10];

bool vis[MAXN+10];
pii A[MAXN+10];

pii operator + (const pii &p, const pii &q) { return {p.first+q.first, p.second+q.second}; }
pii operator - (const pii &p, const pii &q) { return {p.first-q.first, p.second-q.second}; }

bool flag=true, chk;
double val, ans[MAXN+10];
vector<int> V;

void dfs(int now)
{
	vis[now]=true; V.push_back(now);
	for(auto nxt : adj[now])
	{
		if(vis[nxt.first])
		{
			pii t=A[now]+A[nxt.first];
			if(t.first==0)
			{
				if(t.second!=nxt.second) flag=false;
			}
			else
			{
				double p=(double)(nxt.second-t.second)/t.first;
				if(!chk) chk=true, val=p;
				else if(fabs(p-val)>1e-6) flag=false;
			}
		}
		else
		{
			A[nxt.first]=pii(0, nxt.second)-A[now];
			dfs(nxt.first);
		}
	}
}

double f(double x)
{
	double ret=0;
	for(auto it : V) ret+=fabs(A[it].first*x+A[it].second);
	return ret;
}

int main()
{
	scanf("%d%d", &N, &M);
	for(int i=1; i<=M; i++)
	{
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}

	for(int i=1; i<=N; i++)
	{
		if(vis[i]) continue;
		V.clear(); chk=false;
		A[i]=pii(1, 0); dfs(i);
		if(chk)
		{
			for(auto it : V) ans[it]=A[it].first*val+A[it].second;
		}
		else
		{
			double lo=-1e6, hi=1e6;
			for(int j=0; j<500; j++)
			{
				double m1=(lo*2+hi)/3, m2=(lo+hi*2)/3;
				if(f(m1)<=f(m2)) hi=m2;
				else lo=m1;
			}
			for(auto it : V) ans[it]=A[it].first*lo+A[it].second;
		}
	}
	if(!flag) printf("NO\n");
	else
	{
		printf("YES\n");
		for(int i=1; i<=N; i++) printf("%.20f ", ans[i]);
		printf("\n");
	}
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
Graph.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |   scanf("%d%d%d", &u, &v, &w);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2816 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2816 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 3 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 3 ms 2688 KB answer = YES
29 Correct 3 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 3 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2816 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 3 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 3 ms 2688 KB answer = YES
29 Correct 3 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 3 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
37 Correct 4 ms 2688 KB answer = YES
38 Correct 2 ms 2688 KB answer = YES
39 Correct 4 ms 2688 KB answer = YES
40 Correct 3 ms 2688 KB answer = YES
41 Correct 4 ms 2688 KB answer = NO
42 Correct 4 ms 2688 KB answer = YES
43 Correct 5 ms 2688 KB answer = YES
44 Correct 4 ms 2688 KB answer = YES
45 Correct 3 ms 2816 KB answer = YES
46 Correct 3 ms 2688 KB answer = YES
47 Correct 3 ms 2816 KB answer = YES
48 Correct 3 ms 2688 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2816 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 3 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 3 ms 2688 KB answer = YES
29 Correct 3 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 3 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
37 Correct 4 ms 2688 KB answer = YES
38 Correct 2 ms 2688 KB answer = YES
39 Correct 4 ms 2688 KB answer = YES
40 Correct 3 ms 2688 KB answer = YES
41 Correct 4 ms 2688 KB answer = NO
42 Correct 4 ms 2688 KB answer = YES
43 Correct 5 ms 2688 KB answer = YES
44 Correct 4 ms 2688 KB answer = YES
45 Correct 3 ms 2816 KB answer = YES
46 Correct 3 ms 2688 KB answer = YES
47 Correct 3 ms 2816 KB answer = YES
48 Correct 3 ms 2688 KB answer = YES
49 Correct 32 ms 3576 KB answer = YES
50 Correct 12 ms 3712 KB answer = YES
51 Correct 33 ms 3704 KB answer = YES
52 Correct 32 ms 3456 KB answer = NO
53 Correct 5 ms 2816 KB answer = YES
54 Correct 10 ms 2944 KB answer = YES
55 Correct 17 ms 3072 KB answer = YES
56 Correct 33 ms 3576 KB answer = YES
57 Correct 35 ms 3448 KB answer = YES
58 Correct 28 ms 3456 KB answer = YES
59 Correct 11 ms 3456 KB answer = YES
60 Correct 33 ms 3452 KB answer = YES
61 Correct 6 ms 3072 KB answer = YES
62 Correct 87 ms 7852 KB answer = NO
63 Correct 87 ms 8056 KB answer = YES
64 Correct 107 ms 7800 KB answer = NO
65 Correct 86 ms 8056 KB answer = YES
66 Correct 7 ms 2816 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 2 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 2 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 2 ms 2688 KB answer = YES
7 Correct 2 ms 2688 KB answer = YES
8 Correct 2 ms 2688 KB answer = YES
9 Correct 2 ms 2688 KB answer = NO
10 Correct 2 ms 2688 KB answer = YES
11 Correct 2 ms 2816 KB answer = YES
12 Correct 2 ms 2688 KB answer = NO
13 Correct 2 ms 2688 KB answer = YES
14 Correct 2 ms 2688 KB answer = YES
15 Correct 2 ms 2688 KB answer = YES
16 Correct 2 ms 2688 KB answer = YES
17 Correct 2 ms 2688 KB answer = YES
18 Correct 2 ms 2688 KB answer = YES
19 Correct 2 ms 2688 KB answer = YES
20 Correct 2 ms 2688 KB answer = YES
21 Correct 2 ms 2688 KB answer = YES
22 Correct 2 ms 2688 KB answer = NO
23 Correct 2 ms 2688 KB answer = NO
24 Correct 2 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 3 ms 2688 KB answer = YES
27 Correct 2 ms 2688 KB answer = YES
28 Correct 3 ms 2688 KB answer = YES
29 Correct 3 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 3 ms 2688 KB answer = YES
35 Correct 2 ms 2688 KB answer = YES
36 Correct 2 ms 2688 KB answer = YES
37 Correct 4 ms 2688 KB answer = YES
38 Correct 2 ms 2688 KB answer = YES
39 Correct 4 ms 2688 KB answer = YES
40 Correct 3 ms 2688 KB answer = YES
41 Correct 4 ms 2688 KB answer = NO
42 Correct 4 ms 2688 KB answer = YES
43 Correct 5 ms 2688 KB answer = YES
44 Correct 4 ms 2688 KB answer = YES
45 Correct 3 ms 2816 KB answer = YES
46 Correct 3 ms 2688 KB answer = YES
47 Correct 3 ms 2816 KB answer = YES
48 Correct 3 ms 2688 KB answer = YES
49 Correct 32 ms 3576 KB answer = YES
50 Correct 12 ms 3712 KB answer = YES
51 Correct 33 ms 3704 KB answer = YES
52 Correct 32 ms 3456 KB answer = NO
53 Correct 5 ms 2816 KB answer = YES
54 Correct 10 ms 2944 KB answer = YES
55 Correct 17 ms 3072 KB answer = YES
56 Correct 33 ms 3576 KB answer = YES
57 Correct 35 ms 3448 KB answer = YES
58 Correct 28 ms 3456 KB answer = YES
59 Correct 11 ms 3456 KB answer = YES
60 Correct 33 ms 3452 KB answer = YES
61 Correct 6 ms 3072 KB answer = YES
62 Correct 87 ms 7852 KB answer = NO
63 Correct 87 ms 8056 KB answer = YES
64 Correct 107 ms 7800 KB answer = NO
65 Correct 86 ms 8056 KB answer = YES
66 Correct 7 ms 2816 KB answer = YES
67 Incorrect 281 ms 15148 KB participant answer is too inprecise
68 Halted 0 ms 0 KB -