Submission #342900

# Submission time Handle Problem Language Result Execution time Memory
342900 2021-01-03T07:54:30 Z urd05 Graph (BOI20_graph) C++14
100 / 100
170 ms 17428 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
vector<P> adj[100000];
P arr[100000];
bool visited[100000];
int ret[100000];
int chosen=-1e9; //두 배를 저장
const int nn=-1e9;
vector<int> save;

void dfs(int v,int x,int y) {
    if (visited[v]) {
        if (chosen==nn) {
            if (arr[v].first==x) {
                if (arr[v].second!=y) {
                    printf("NO");
                    exit(0);
                }
            }
            else {
                chosen=(2*(arr[v].second-y))/(x-arr[v].first);
            }
        }
        else  {
            if (x*chosen+y*2!=arr[v].first*chosen+arr[v].second*2) {
                printf("NO");
                exit(0);
            }
        }
        return;
    }
    visited[v]=true;
    save.push_back(v);
    arr[v].first=x;
    arr[v].second=y;
    for(int i=0;i<adj[v].size();i++) {
        dfs(adj[v][i].first,-x,-y+adj[v][i].second);
    }
}

int main(void) {
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++) {
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        u--;
        v--;
        adj[u].push_back(P(v,c));
        adj[v].push_back(P(u,c));
    }
    for(int v=0;v<n;v++) {
        if (!visited[v]) {
            chosen=nn;
            arr[v]=P(1,0);
            dfs(v,1,0);
            if (chosen==nn) {
                vector<int> vec;
                for(int i=0;i<save.size();i++) {
                    int now=save[i];
                    if (arr[now].first==1) {
                        vec.push_back(-arr[now].second);
                    }
                    else if (arr[now].first==-1) {
                        vec.push_back(arr[now].second);
                    }
                }
                sort(vec.begin(),vec.end());
                chosen=vec[vec.size()/2]*2;
            }
            for(int i=0;i<save.size();i++) {
                int now=save[i];
                ret[now]=arr[now].first*chosen+arr[now].second*2;
            }
            save.clear();
        }
    }
    printf("YES\n");
    for(int i=0;i<n;i++) {
        if (ret[i]>=0)
            printf("%d.%d ",ret[i]/2,(ret[i]%2)*5);
        else
            printf("-%d.%d ",(-ret[i])/2,((-ret[i])%2)*5);
    }
}

Compilation message

Graph.cpp: In function 'void dfs(int, int, int)':
Graph.cpp:38: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]
   38 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:61:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                 for(int i=0;i<save.size();i++) {
      |                             ~^~~~~~~~~~~~
Graph.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             for(int i=0;i<save.size();i++) {
      |                         ~^~~~~~~~~~~~
Graph.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%d %d %d",&u,&v,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 2688 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
# Verdict Execution time Memory 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 2688 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 3 ms 2668 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2816 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
# Verdict Execution time Memory 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 2688 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 3 ms 2668 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2816 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 2668 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 2 ms 2796 KB answer = YES
44 Correct 2 ms 2796 KB answer = YES
45 Correct 3 ms 2796 KB answer = YES
46 Correct 2 ms 2668 KB answer = YES
47 Correct 3 ms 2796 KB answer = YES
48 Correct 2 ms 2796 KB answer = YES
# Verdict Execution time Memory 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 2688 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 3 ms 2668 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2816 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 2668 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 2 ms 2796 KB answer = YES
44 Correct 2 ms 2796 KB answer = YES
45 Correct 3 ms 2796 KB answer = YES
46 Correct 2 ms 2668 KB answer = YES
47 Correct 3 ms 2796 KB answer = YES
48 Correct 2 ms 2796 KB answer = YES
49 Correct 8 ms 3308 KB answer = YES
50 Correct 8 ms 3564 KB answer = YES
51 Correct 9 ms 3692 KB answer = YES
52 Correct 6 ms 3180 KB answer = NO
53 Correct 3 ms 2796 KB answer = YES
54 Correct 3 ms 2796 KB answer = YES
55 Correct 7 ms 3052 KB answer = YES
56 Correct 8 ms 3308 KB answer = YES
57 Correct 8 ms 3308 KB answer = YES
58 Correct 8 ms 3308 KB answer = YES
59 Correct 7 ms 3180 KB answer = YES
60 Correct 9 ms 3308 KB answer = YES
61 Correct 5 ms 3052 KB answer = YES
62 Correct 74 ms 7384 KB answer = NO
63 Correct 80 ms 8044 KB answer = YES
64 Correct 77 ms 8044 KB answer = NO
65 Correct 82 ms 8184 KB answer = YES
66 Correct 3 ms 2796 KB answer = YES
# Verdict Execution time Memory 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 2688 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 3 ms 2668 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 2 ms 2668 KB answer = YES
33 Correct 2 ms 2816 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 2668 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 2 ms 2796 KB answer = YES
44 Correct 2 ms 2796 KB answer = YES
45 Correct 3 ms 2796 KB answer = YES
46 Correct 2 ms 2668 KB answer = YES
47 Correct 3 ms 2796 KB answer = YES
48 Correct 2 ms 2796 KB answer = YES
49 Correct 8 ms 3308 KB answer = YES
50 Correct 8 ms 3564 KB answer = YES
51 Correct 9 ms 3692 KB answer = YES
52 Correct 6 ms 3180 KB answer = NO
53 Correct 3 ms 2796 KB answer = YES
54 Correct 3 ms 2796 KB answer = YES
55 Correct 7 ms 3052 KB answer = YES
56 Correct 8 ms 3308 KB answer = YES
57 Correct 8 ms 3308 KB answer = YES
58 Correct 8 ms 3308 KB answer = YES
59 Correct 7 ms 3180 KB answer = YES
60 Correct 9 ms 3308 KB answer = YES
61 Correct 5 ms 3052 KB answer = YES
62 Correct 74 ms 7384 KB answer = NO
63 Correct 80 ms 8044 KB answer = YES
64 Correct 77 ms 8044 KB answer = NO
65 Correct 82 ms 8184 KB answer = YES
66 Correct 3 ms 2796 KB answer = YES
67 Correct 66 ms 14440 KB answer = YES
68 Correct 68 ms 14312 KB answer = YES
69 Correct 65 ms 14316 KB answer = YES
70 Correct 109 ms 17428 KB answer = YES
71 Correct 65 ms 14316 KB answer = YES
72 Correct 89 ms 8672 KB answer = YES
73 Correct 83 ms 8600 KB answer = YES
74 Correct 52 ms 9456 KB answer = YES
75 Correct 32 ms 7148 KB answer = NO
76 Correct 10 ms 3564 KB answer = YES
77 Correct 19 ms 4232 KB answer = YES
78 Correct 33 ms 5316 KB answer = YES
79 Correct 73 ms 7980 KB answer = YES
80 Correct 50 ms 9464 KB answer = YES
81 Correct 54 ms 10476 KB answer = NO
82 Correct 79 ms 13804 KB answer = YES
83 Correct 96 ms 14444 KB answer = YES
84 Correct 107 ms 14440 KB answer = YES
85 Correct 67 ms 14440 KB answer = YES
86 Correct 63 ms 14444 KB answer = YES
87 Correct 63 ms 9068 KB answer = NO
88 Correct 99 ms 10480 KB answer = YES
89 Correct 73 ms 7532 KB answer = YES
90 Correct 78 ms 7532 KB answer = YES
91 Correct 86 ms 7532 KB answer = YES
92 Correct 40 ms 5736 KB answer = YES
93 Correct 38 ms 5736 KB answer = YES
94 Correct 74 ms 13520 KB answer = NO
95 Correct 59 ms 7148 KB answer = NO
96 Correct 170 ms 14820 KB answer = YES
97 Correct 46 ms 13420 KB answer = NO