답안 #558363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558363 2022-05-07T07:32:50 Z hibiki Graph (BOI20_graph) C++11
100 / 100
147 ms 22476 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second

int n,m;
int na[100005],nb[100005];
double x,ans[100005];
bool done[100005],found;
vector<int> has;
vector<pair<int,int> > v[100005];

void dfs(int nw, int fa)
{
    has.pb(nw);

    for(pair<int,int> go: v[nw])
    {
        if(go.F == fa) continue;

        int ga = na[nw] * -1, gb = go.S - nb[nw];

        if(!done[go.F])
        {
            done[go.F] = true;
            na[go.F] = ga;
            nb[go.F] = gb;
            dfs(go.F,nw);
        }
        else if(na[go.F] != ga)
        {
            double temp = (double)(nb[go.F] - gb) / (double)(ga - na[go.F]);
            if(found && temp != x)
            {
                printf("NO\n");
                exit(0);
            }
            x = temp;
            found = true;
        }
        else if(nb[go.F] != gb)
        {
            printf("NO\n");
            exit(0);
        }
    }
}

int main()
{
    scanf("%d %d",&n,&m);
    for(int i = 0; i < m; i++)
    {
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        v[a].pb({b,c});
        v[b].pb({a,c});
    }

    for(int i = 1; i <= n; i++)
    {
        if(done[i]) continue;

        has.clear();
        found = false;

        done[i] = true;
        na[i] = 1;
        nb[i] = 0;
        dfs(i,-1);

        if(!found)
        {
            vector<int> ss;
            for(int po: has)
                ss.pb(-na[po] * nb[po]);

            sort(ss.begin(),ss.end());

            x = (double)ss[ss.size() / 2];
        }

        for(int po: has)
            ans[po] = na[po] * x + nb[po];
    }

    printf("YES\n");
    for(int i = 1; i <= n; i++)
        printf("%lf ",ans[i]);
    printf("\n");

    return 0;
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         scanf("%d %d %d",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 3 ms 2648 KB answer = YES
20 Correct 2 ms 2656 KB answer = YES
21 Correct 3 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 3 ms 2648 KB answer = YES
20 Correct 2 ms 2656 KB answer = YES
21 Correct 3 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2660 KB answer = YES
28 Correct 3 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2660 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 2 ms 2660 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 3 ms 2648 KB answer = YES
20 Correct 2 ms 2656 KB answer = YES
21 Correct 3 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2660 KB answer = YES
28 Correct 3 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2660 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 2 ms 2660 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2652 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2664 KB answer = YES
41 Correct 2 ms 2664 KB answer = NO
42 Correct 3 ms 2644 KB answer = YES
43 Correct 3 ms 2644 KB answer = YES
44 Correct 2 ms 2644 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2660 KB answer = YES
47 Correct 2 ms 2644 KB answer = YES
48 Correct 2 ms 2644 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 3 ms 2648 KB answer = YES
20 Correct 2 ms 2656 KB answer = YES
21 Correct 3 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2660 KB answer = YES
28 Correct 3 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2660 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 2 ms 2660 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2652 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2664 KB answer = YES
41 Correct 2 ms 2664 KB answer = NO
42 Correct 3 ms 2644 KB answer = YES
43 Correct 3 ms 2644 KB answer = YES
44 Correct 2 ms 2644 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2660 KB answer = YES
47 Correct 2 ms 2644 KB answer = YES
48 Correct 2 ms 2644 KB answer = YES
49 Correct 9 ms 3540 KB answer = YES
50 Correct 11 ms 3860 KB answer = YES
51 Correct 10 ms 3924 KB answer = YES
52 Correct 6 ms 3156 KB answer = NO
53 Correct 4 ms 2664 KB answer = YES
54 Correct 3 ms 2772 KB answer = YES
55 Correct 6 ms 3056 KB answer = YES
56 Correct 12 ms 3540 KB answer = YES
57 Correct 8 ms 3308 KB answer = YES
58 Correct 8 ms 3412 KB answer = YES
59 Correct 8 ms 3284 KB answer = YES
60 Correct 9 ms 3412 KB answer = YES
61 Correct 5 ms 3008 KB answer = YES
62 Correct 63 ms 9664 KB answer = NO
63 Correct 72 ms 10336 KB answer = YES
64 Correct 85 ms 10184 KB answer = NO
65 Correct 66 ms 10344 KB answer = YES
66 Correct 4 ms 2800 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 2 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 1 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 1 ms 2644 KB answer = YES
9 Correct 1 ms 2644 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 1 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 1 ms 2644 KB answer = YES
16 Correct 1 ms 2644 KB answer = YES
17 Correct 2 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 3 ms 2648 KB answer = YES
20 Correct 2 ms 2656 KB answer = YES
21 Correct 3 ms 2644 KB answer = YES
22 Correct 2 ms 2644 KB answer = NO
23 Correct 2 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2660 KB answer = YES
28 Correct 3 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2644 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2660 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 2 ms 2660 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2652 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 2 ms 2664 KB answer = YES
41 Correct 2 ms 2664 KB answer = NO
42 Correct 3 ms 2644 KB answer = YES
43 Correct 3 ms 2644 KB answer = YES
44 Correct 2 ms 2644 KB answer = YES
45 Correct 2 ms 2644 KB answer = YES
46 Correct 2 ms 2660 KB answer = YES
47 Correct 2 ms 2644 KB answer = YES
48 Correct 2 ms 2644 KB answer = YES
49 Correct 9 ms 3540 KB answer = YES
50 Correct 11 ms 3860 KB answer = YES
51 Correct 10 ms 3924 KB answer = YES
52 Correct 6 ms 3156 KB answer = NO
53 Correct 4 ms 2664 KB answer = YES
54 Correct 3 ms 2772 KB answer = YES
55 Correct 6 ms 3056 KB answer = YES
56 Correct 12 ms 3540 KB answer = YES
57 Correct 8 ms 3308 KB answer = YES
58 Correct 8 ms 3412 KB answer = YES
59 Correct 8 ms 3284 KB answer = YES
60 Correct 9 ms 3412 KB answer = YES
61 Correct 5 ms 3008 KB answer = YES
62 Correct 63 ms 9664 KB answer = NO
63 Correct 72 ms 10336 KB answer = YES
64 Correct 85 ms 10184 KB answer = NO
65 Correct 66 ms 10344 KB answer = YES
66 Correct 4 ms 2800 KB answer = YES
67 Correct 74 ms 18136 KB answer = YES
68 Correct 69 ms 18000 KB answer = YES
69 Correct 77 ms 17980 KB answer = YES
70 Correct 101 ms 22476 KB answer = YES
71 Correct 73 ms 17992 KB answer = YES
72 Correct 75 ms 10756 KB answer = YES
73 Correct 111 ms 10820 KB answer = YES
74 Correct 55 ms 11752 KB answer = YES
75 Correct 32 ms 8252 KB answer = NO
76 Correct 10 ms 3668 KB answer = YES
77 Correct 20 ms 4724 KB answer = YES
78 Correct 31 ms 6200 KB answer = YES
79 Correct 68 ms 9672 KB answer = YES
80 Correct 60 ms 11712 KB answer = YES
81 Correct 60 ms 12632 KB answer = NO
82 Correct 81 ms 17488 KB answer = YES
83 Correct 103 ms 18252 KB answer = YES
84 Correct 120 ms 18048 KB answer = YES
85 Correct 76 ms 18132 KB answer = YES
86 Correct 73 ms 18144 KB answer = YES
87 Correct 57 ms 11324 KB answer = NO
88 Correct 115 ms 13316 KB answer = YES
89 Correct 74 ms 9580 KB answer = YES
90 Correct 75 ms 9604 KB answer = YES
91 Correct 101 ms 9676 KB answer = YES
92 Correct 35 ms 6756 KB answer = YES
93 Correct 35 ms 6716 KB answer = YES
94 Correct 80 ms 16276 KB answer = NO
95 Correct 51 ms 8672 KB answer = NO
96 Correct 147 ms 19284 KB answer = YES
97 Correct 54 ms 16272 KB answer = NO