답안 #342896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342896 2021-01-03T07:49:18 Z leinad2 Graph (BOI20_graph) C++17
100 / 100
204 ms 24036 KB
#include<bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, b, c, vis[100010], A[100010][2];
vector<pair<int, int> >adj[100010];
double ans[100010];
bool flag=true;
vector<double>V;
vector<int>chk;
void dfs(int v)
{
    chk.push_back(v);
    for(int i=0;i<adj[v].size();i++)
    {
        int p=adj[v][i].first;
        if(!vis[p])
        {
            vis[p]=1;
            A[p][0]=-A[v][0];
            A[p][1]=adj[v][i].second-A[v][1];
            dfs(p);
        }
        else
        {
            if(A[p][0]==A[v][0])
            {
                V.push_back((double)(adj[v][i].second-A[p][1]-A[v][1])/(A[p][0]+A[v][0]));
            }
            else
            {
                if(A[p][1]+A[v][1]!=adj[v][i].second)
                {
                    flag=false;
                }
            }
        }
    }
}
int main()
{
    for(scanf("%d %d", &n, &m);i++<m;)
    {
        scanf("%d %d %d", &a, &b, &c);
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    for(i=0;i++<n;)
    {
        if(!vis[i])
        {
            V.clear();
            chk.clear();
            vis[i]=1;
            A[i][0]=1;
            A[i][1]=0;
            dfs(i);
            if(flag==false)
            {
                puts("NO");
                return 0;
            }
            if(V.size())
            {
                for(j=1;j<V.size();j++)
                {
                    if(V[j]!=V[0])
                    {
                        puts("NO");
                        return 0;
                    }
                }
                for(j=0;j<chk.size();j++)
                {
                    k=chk[j];
                    ans[k]=(double)A[k][0]*V[0]+(double)A[k][1];
                }
            }
            else
            {
                vector<int>v;
                for(j=0;j<chk.size();j++)
                {
                    k=chk[j];
                    v.push_back(-(A[k][1]/A[k][0]));
                }
                sort(v.begin(), v.end());
                double a=(double)(v[v.size()/2]);
                for(j=0;j<chk.size();j++)
                {
                    k=chk[j];
                    ans[k]=a*(double)A[k][0]+(double)A[k][1];
                }
            }
        }
    }
    puts("YES");
    for(i=0;i++<n;)printf("%.10lf ", ans[i]);
}

Compilation message

Graph.cpp: In function 'void dfs(int)':
Graph.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<adj[v].size();i++)
      |                 ~^~~~~~~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |                 for(j=1;j<V.size();j++)
      |                         ~^~~~~~~~~
Graph.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |                 for(j=0;j<chk.size();j++)
      |                         ~^~~~~~~~~~~
Graph.cpp:80:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                 for(j=0;j<chk.size();j++)
      |                         ~^~~~~~~~~~~
Graph.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |                 for(j=0;j<chk.size();j++)
      |                         ~^~~~~~~~~~~
Graph.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |     for(scanf("%d %d", &n, &m);i++<m;)
      |         ~~~~~^~~~~~~~~~~~~~~~~
Graph.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         scanf("%d %d %d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB answer = YES
2 Correct 2 ms 2668 KB answer = YES
3 Correct 2 ms 2668 KB answer = YES
4 Correct 2 ms 2668 KB answer = NO
5 Correct 2 ms 2668 KB answer = YES
6 Correct 2 ms 2668 KB answer = YES
7 Correct 2 ms 2668 KB answer = YES
8 Correct 2 ms 2668 KB answer = YES
9 Correct 2 ms 2668 KB answer = NO
10 Correct 2 ms 2668 KB answer = YES
11 Correct 2 ms 2668 KB answer = YES
12 Correct 2 ms 2668 KB answer = NO
13 Correct 2 ms 2668 KB answer = YES
14 Correct 2 ms 2668 KB answer = YES
15 Correct 2 ms 2668 KB answer = YES
16 Correct 2 ms 2668 KB answer = YES
17 Correct 2 ms 2668 KB answer = YES
18 Correct 2 ms 2668 KB answer = YES
19 Correct 2 ms 2668 KB answer = YES
20 Correct 2 ms 2668 KB answer = YES
21 Correct 2 ms 2668 KB answer = YES
22 Correct 2 ms 2668 KB answer = NO
23 Correct 2 ms 2668 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB answer = YES
2 Correct 2 ms 2668 KB answer = YES
3 Correct 2 ms 2668 KB answer = YES
4 Correct 2 ms 2668 KB answer = NO
5 Correct 2 ms 2668 KB answer = YES
6 Correct 2 ms 2668 KB answer = YES
7 Correct 2 ms 2668 KB answer = YES
8 Correct 2 ms 2668 KB answer = YES
9 Correct 2 ms 2668 KB answer = NO
10 Correct 2 ms 2668 KB answer = YES
11 Correct 2 ms 2668 KB answer = YES
12 Correct 2 ms 2668 KB answer = NO
13 Correct 2 ms 2668 KB answer = YES
14 Correct 2 ms 2668 KB answer = YES
15 Correct 2 ms 2668 KB answer = YES
16 Correct 2 ms 2668 KB answer = YES
17 Correct 2 ms 2668 KB answer = YES
18 Correct 2 ms 2668 KB answer = YES
19 Correct 2 ms 2668 KB answer = YES
20 Correct 2 ms 2668 KB answer = YES
21 Correct 2 ms 2668 KB answer = YES
22 Correct 2 ms 2668 KB answer = NO
23 Correct 2 ms 2668 KB answer = NO
24 Correct 2 ms 2668 KB answer = YES
25 Correct 2 ms 2668 KB answer = YES
26 Correct 2 ms 2668 KB answer = YES
27 Correct 2 ms 2668 KB answer = YES
28 Correct 2 ms 2668 KB answer = YES
29 Correct 2 ms 2668 KB answer = YES
30 Correct 2 ms 2668 KB answer = NO
31 Correct 2 ms 2668 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2668 KB answer = YES
34 Correct 2 ms 2668 KB answer = YES
35 Correct 2 ms 2668 KB answer = YES
36 Correct 2 ms 2668 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB answer = YES
2 Correct 2 ms 2668 KB answer = YES
3 Correct 2 ms 2668 KB answer = YES
4 Correct 2 ms 2668 KB answer = NO
5 Correct 2 ms 2668 KB answer = YES
6 Correct 2 ms 2668 KB answer = YES
7 Correct 2 ms 2668 KB answer = YES
8 Correct 2 ms 2668 KB answer = YES
9 Correct 2 ms 2668 KB answer = NO
10 Correct 2 ms 2668 KB answer = YES
11 Correct 2 ms 2668 KB answer = YES
12 Correct 2 ms 2668 KB answer = NO
13 Correct 2 ms 2668 KB answer = YES
14 Correct 2 ms 2668 KB answer = YES
15 Correct 2 ms 2668 KB answer = YES
16 Correct 2 ms 2668 KB answer = YES
17 Correct 2 ms 2668 KB answer = YES
18 Correct 2 ms 2668 KB answer = YES
19 Correct 2 ms 2668 KB answer = YES
20 Correct 2 ms 2668 KB answer = YES
21 Correct 2 ms 2668 KB answer = YES
22 Correct 2 ms 2668 KB answer = NO
23 Correct 2 ms 2668 KB answer = NO
24 Correct 2 ms 2668 KB answer = YES
25 Correct 2 ms 2668 KB answer = YES
26 Correct 2 ms 2668 KB answer = YES
27 Correct 2 ms 2668 KB answer = YES
28 Correct 2 ms 2668 KB answer = YES
29 Correct 2 ms 2668 KB answer = YES
30 Correct 2 ms 2668 KB answer = NO
31 Correct 2 ms 2668 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2668 KB answer = YES
34 Correct 2 ms 2668 KB answer = YES
35 Correct 2 ms 2668 KB answer = YES
36 Correct 2 ms 2668 KB answer = YES
37 Correct 2 ms 2668 KB answer = YES
38 Correct 2 ms 2668 KB answer = YES
39 Correct 2 ms 2796 KB answer = YES
40 Correct 3 ms 2796 KB answer = YES
41 Correct 2 ms 2796 KB answer = NO
42 Correct 3 ms 2796 KB answer = YES
43 Correct 3 ms 2796 KB answer = YES
44 Correct 3 ms 2796 KB answer = YES
45 Correct 3 ms 2796 KB answer = YES
46 Correct 2 ms 2796 KB answer = YES
47 Correct 3 ms 2796 KB answer = YES
48 Correct 3 ms 2796 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB answer = YES
2 Correct 2 ms 2668 KB answer = YES
3 Correct 2 ms 2668 KB answer = YES
4 Correct 2 ms 2668 KB answer = NO
5 Correct 2 ms 2668 KB answer = YES
6 Correct 2 ms 2668 KB answer = YES
7 Correct 2 ms 2668 KB answer = YES
8 Correct 2 ms 2668 KB answer = YES
9 Correct 2 ms 2668 KB answer = NO
10 Correct 2 ms 2668 KB answer = YES
11 Correct 2 ms 2668 KB answer = YES
12 Correct 2 ms 2668 KB answer = NO
13 Correct 2 ms 2668 KB answer = YES
14 Correct 2 ms 2668 KB answer = YES
15 Correct 2 ms 2668 KB answer = YES
16 Correct 2 ms 2668 KB answer = YES
17 Correct 2 ms 2668 KB answer = YES
18 Correct 2 ms 2668 KB answer = YES
19 Correct 2 ms 2668 KB answer = YES
20 Correct 2 ms 2668 KB answer = YES
21 Correct 2 ms 2668 KB answer = YES
22 Correct 2 ms 2668 KB answer = NO
23 Correct 2 ms 2668 KB answer = NO
24 Correct 2 ms 2668 KB answer = YES
25 Correct 2 ms 2668 KB answer = YES
26 Correct 2 ms 2668 KB answer = YES
27 Correct 2 ms 2668 KB answer = YES
28 Correct 2 ms 2668 KB answer = YES
29 Correct 2 ms 2668 KB answer = YES
30 Correct 2 ms 2668 KB answer = NO
31 Correct 2 ms 2668 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2668 KB answer = YES
34 Correct 2 ms 2668 KB answer = YES
35 Correct 2 ms 2668 KB answer = YES
36 Correct 2 ms 2668 KB answer = YES
37 Correct 2 ms 2668 KB answer = YES
38 Correct 2 ms 2668 KB answer = YES
39 Correct 2 ms 2796 KB answer = YES
40 Correct 3 ms 2796 KB answer = YES
41 Correct 2 ms 2796 KB answer = NO
42 Correct 3 ms 2796 KB answer = YES
43 Correct 3 ms 2796 KB answer = YES
44 Correct 3 ms 2796 KB answer = YES
45 Correct 3 ms 2796 KB answer = YES
46 Correct 2 ms 2796 KB answer = YES
47 Correct 3 ms 2796 KB answer = YES
48 Correct 3 ms 2796 KB answer = YES
49 Correct 10 ms 3692 KB answer = YES
50 Correct 11 ms 3948 KB answer = YES
51 Correct 13 ms 4076 KB answer = YES
52 Correct 7 ms 3820 KB answer = NO
53 Correct 3 ms 2796 KB answer = YES
54 Correct 4 ms 2924 KB answer = YES
55 Correct 6 ms 3180 KB answer = YES
56 Correct 10 ms 3692 KB answer = YES
57 Correct 10 ms 3564 KB answer = YES
58 Correct 10 ms 3564 KB answer = YES
59 Correct 9 ms 3436 KB answer = YES
60 Correct 10 ms 3564 KB answer = YES
61 Correct 6 ms 3180 KB answer = YES
62 Correct 87 ms 12548 KB answer = NO
63 Correct 88 ms 12548 KB answer = YES
64 Correct 83 ms 12548 KB answer = NO
65 Correct 87 ms 12548 KB answer = YES
66 Correct 4 ms 2924 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB answer = YES
2 Correct 2 ms 2668 KB answer = YES
3 Correct 2 ms 2668 KB answer = YES
4 Correct 2 ms 2668 KB answer = NO
5 Correct 2 ms 2668 KB answer = YES
6 Correct 2 ms 2668 KB answer = YES
7 Correct 2 ms 2668 KB answer = YES
8 Correct 2 ms 2668 KB answer = YES
9 Correct 2 ms 2668 KB answer = NO
10 Correct 2 ms 2668 KB answer = YES
11 Correct 2 ms 2668 KB answer = YES
12 Correct 2 ms 2668 KB answer = NO
13 Correct 2 ms 2668 KB answer = YES
14 Correct 2 ms 2668 KB answer = YES
15 Correct 2 ms 2668 KB answer = YES
16 Correct 2 ms 2668 KB answer = YES
17 Correct 2 ms 2668 KB answer = YES
18 Correct 2 ms 2668 KB answer = YES
19 Correct 2 ms 2668 KB answer = YES
20 Correct 2 ms 2668 KB answer = YES
21 Correct 2 ms 2668 KB answer = YES
22 Correct 2 ms 2668 KB answer = NO
23 Correct 2 ms 2668 KB answer = NO
24 Correct 2 ms 2668 KB answer = YES
25 Correct 2 ms 2668 KB answer = YES
26 Correct 2 ms 2668 KB answer = YES
27 Correct 2 ms 2668 KB answer = YES
28 Correct 2 ms 2668 KB answer = YES
29 Correct 2 ms 2668 KB answer = YES
30 Correct 2 ms 2668 KB answer = NO
31 Correct 2 ms 2668 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2668 KB answer = YES
34 Correct 2 ms 2668 KB answer = YES
35 Correct 2 ms 2668 KB answer = YES
36 Correct 2 ms 2668 KB answer = YES
37 Correct 2 ms 2668 KB answer = YES
38 Correct 2 ms 2668 KB answer = YES
39 Correct 2 ms 2796 KB answer = YES
40 Correct 3 ms 2796 KB answer = YES
41 Correct 2 ms 2796 KB answer = NO
42 Correct 3 ms 2796 KB answer = YES
43 Correct 3 ms 2796 KB answer = YES
44 Correct 3 ms 2796 KB answer = YES
45 Correct 3 ms 2796 KB answer = YES
46 Correct 2 ms 2796 KB answer = YES
47 Correct 3 ms 2796 KB answer = YES
48 Correct 3 ms 2796 KB answer = YES
49 Correct 10 ms 3692 KB answer = YES
50 Correct 11 ms 3948 KB answer = YES
51 Correct 13 ms 4076 KB answer = YES
52 Correct 7 ms 3820 KB answer = NO
53 Correct 3 ms 2796 KB answer = YES
54 Correct 4 ms 2924 KB answer = YES
55 Correct 6 ms 3180 KB answer = YES
56 Correct 10 ms 3692 KB answer = YES
57 Correct 10 ms 3564 KB answer = YES
58 Correct 10 ms 3564 KB answer = YES
59 Correct 9 ms 3436 KB answer = YES
60 Correct 10 ms 3564 KB answer = YES
61 Correct 6 ms 3180 KB answer = YES
62 Correct 87 ms 12548 KB answer = NO
63 Correct 88 ms 12548 KB answer = YES
64 Correct 83 ms 12548 KB answer = NO
65 Correct 87 ms 12548 KB answer = YES
66 Correct 4 ms 2924 KB answer = YES
67 Correct 95 ms 18920 KB answer = YES
68 Correct 84 ms 18792 KB answer = YES
69 Correct 81 ms 18864 KB answer = YES
70 Correct 128 ms 24036 KB answer = YES
71 Correct 83 ms 18796 KB answer = YES
72 Correct 107 ms 11608 KB answer = YES
73 Correct 111 ms 11560 KB answer = YES
74 Correct 68 ms 12144 KB answer = YES
75 Correct 36 ms 10736 KB answer = NO
76 Correct 13 ms 3820 KB answer = YES
77 Correct 24 ms 5000 KB answer = YES
78 Correct 44 ms 6528 KB answer = YES
79 Correct 90 ms 10260 KB answer = YES
80 Correct 73 ms 12140 KB answer = YES
81 Correct 60 ms 12908 KB answer = NO
82 Correct 110 ms 18156 KB answer = YES
83 Correct 131 ms 18924 KB answer = YES
84 Correct 131 ms 18920 KB answer = YES
85 Correct 99 ms 18920 KB answer = YES
86 Correct 96 ms 18924 KB answer = YES
87 Correct 71 ms 11628 KB answer = NO
88 Correct 128 ms 14064 KB answer = YES
89 Correct 93 ms 10476 KB answer = YES
90 Correct 96 ms 10476 KB answer = YES
91 Correct 109 ms 10476 KB answer = YES
92 Correct 48 ms 7272 KB answer = YES
93 Correct 47 ms 7272 KB answer = YES
94 Correct 87 ms 16620 KB answer = NO
95 Correct 56 ms 9068 KB answer = NO
96 Correct 204 ms 20836 KB answer = YES
97 Correct 47 ms 16620 KB answer = NO