답안 #284128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284128 2020-08-26T21:59:38 Z duality Graph (BOI20_graph) C++11
100 / 100
231 ms 18792 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

vpii adjList[100000];
int visited[100000],ans[100000];
pii f[100000];
vi vv,vv2;
int no = 0,must;
int doDFS(int u,pii ff) {
    if (visited[u]) {
        if (f[u].first == ff.first) {
            if (f[u].second != ff.second) no = 1;
        }
        else {
            if (must == 1e9) must = (ff.second-f[u].second)/(f[u].first-ff.first);
            else if ((ff.second-f[u].second)/(f[u].first-ff.first) != must) no = 1;
        }
        return 0;
    }
    int i;
    visited[u] = 1,f[u] = ff,vv.pb(u);
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i].first;
        doDFS(v,mp(-ff.first,adjList[u][i].second-ff.second));
    }
    return 0;
}
int main() {
    int i;
    int N,M;
    int a,b,c;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) {
        scanf("%d %d %d",&a,&b,&c);
        a--,b--;
        adjList[a].pb(mp(b,2*c));
        adjList[b].pb(mp(a,2*c));
    }

    int j;
    for (i = 0; i < N; i++) {
        if (!visited[i]) {
            must = 1e9,vv.clear();
            doDFS(i,mp(1,0));
            if (no) break;
            else if (must != 1e9) {
                for (j = 0; j < vv.size(); j++) ans[vv[j]] = f[vv[j]].first*must+f[vv[j]].second;
            }
            else {
                for (j = 0; j < vv.size(); j++) vv2.pb(-f[vv[j]].first*f[vv[j]].second);
                nth_element(vv2.begin(),vv2.begin()+(vv2.size()-1)/2,vv2.end());
                must = vv2[(vv2.size()-1)/2];
                for (j = 0; j < vv.size(); j++) ans[vv[j]] = f[vv[j]].first*must+f[vv[j]].second;
                vv2.clear();
            }
        }
    }
    if (no) printf("NO\n");
    else {
        printf("YES\n");
        for (i = 0; i < N; i++) {
            if (ans[i] >= 0) printf("%d.%c ",ans[i]/2,(ans[i] & 1) ? '5':'0');
            else printf("-%d.%c ",(-ans[i])/2,((-ans[i]) & 1) ? '5':'0');
        }
        printf("\n");
    }

    return 0;
}

Compilation message

Graph.cpp: In function 'int doDFS(int, pii)':
Graph.cpp:76:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for (i = 0; i < adjList[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:101:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |                 for (j = 0; j < vv.size(); j++) ans[vv[j]] = f[vv[j]].first*must+f[vv[j]].second;
      |                             ~~^~~~~~~~~~~
Graph.cpp:104:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |                 for (j = 0; j < vv.size(); j++) vv2.pb(-f[vv[j]].first*f[vv[j]].second);
      |                             ~~^~~~~~~~~~~
Graph.cpp:107:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |                 for (j = 0; j < vv.size(); j++) ans[vv[j]] = f[vv[j]].first*must+f[vv[j]].second;
      |                             ~~^~~~~~~~~~~
Graph.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:88:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   88 |         scanf("%d %d %d",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 2664 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 2688 KB answer = YES
12 Correct 3 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 2816 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
# 결과 실행 시간 메모리 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 2664 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 2688 KB answer = YES
12 Correct 3 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 2816 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 3 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2724 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 3 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
# 결과 실행 시간 메모리 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 2664 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 2688 KB answer = YES
12 Correct 3 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 2816 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 3 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2724 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 3 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 2 ms 2688 KB answer = YES
38 Correct 2 ms 2640 KB answer = YES
39 Correct 3 ms 2688 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 3 ms 2816 KB answer = NO
42 Correct 4 ms 2816 KB answer = YES
43 Correct 3 ms 2816 KB answer = YES
44 Correct 3 ms 2816 KB answer = YES
45 Correct 3 ms 2736 KB answer = YES
46 Correct 2 ms 2816 KB answer = YES
47 Correct 3 ms 2792 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
# 결과 실행 시간 메모리 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 2664 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 2688 KB answer = YES
12 Correct 3 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 2816 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 3 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2724 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 3 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 2 ms 2688 KB answer = YES
38 Correct 2 ms 2640 KB answer = YES
39 Correct 3 ms 2688 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 3 ms 2816 KB answer = NO
42 Correct 4 ms 2816 KB answer = YES
43 Correct 3 ms 2816 KB answer = YES
44 Correct 3 ms 2816 KB answer = YES
45 Correct 3 ms 2736 KB answer = YES
46 Correct 2 ms 2816 KB answer = YES
47 Correct 3 ms 2792 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
49 Correct 9 ms 3456 KB answer = YES
50 Correct 10 ms 3712 KB answer = YES
51 Correct 9 ms 3712 KB answer = YES
52 Correct 7 ms 3712 KB answer = NO
53 Correct 3 ms 2816 KB answer = YES
54 Correct 4 ms 2944 KB answer = YES
55 Correct 6 ms 3120 KB answer = YES
56 Correct 11 ms 3456 KB answer = YES
57 Correct 9 ms 3328 KB answer = YES
58 Correct 8 ms 3328 KB answer = YES
59 Correct 10 ms 3328 KB answer = YES
60 Correct 9 ms 3456 KB answer = YES
61 Correct 6 ms 3072 KB answer = YES
62 Correct 100 ms 10104 KB answer = NO
63 Correct 104 ms 10232 KB answer = YES
64 Correct 107 ms 10104 KB answer = NO
65 Correct 108 ms 10232 KB answer = YES
66 Correct 4 ms 2816 KB answer = YES
# 결과 실행 시간 메모리 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 2664 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 2688 KB answer = YES
12 Correct 3 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 2816 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 3 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2724 KB answer = YES
28 Correct 2 ms 2688 KB answer = YES
29 Correct 2 ms 2688 KB answer = YES
30 Correct 2 ms 2688 KB answer = NO
31 Correct 2 ms 2688 KB answer = YES
32 Correct 3 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 2 ms 2688 KB answer = YES
38 Correct 2 ms 2640 KB answer = YES
39 Correct 3 ms 2688 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 3 ms 2816 KB answer = NO
42 Correct 4 ms 2816 KB answer = YES
43 Correct 3 ms 2816 KB answer = YES
44 Correct 3 ms 2816 KB answer = YES
45 Correct 3 ms 2736 KB answer = YES
46 Correct 2 ms 2816 KB answer = YES
47 Correct 3 ms 2792 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
49 Correct 9 ms 3456 KB answer = YES
50 Correct 10 ms 3712 KB answer = YES
51 Correct 9 ms 3712 KB answer = YES
52 Correct 7 ms 3712 KB answer = NO
53 Correct 3 ms 2816 KB answer = YES
54 Correct 4 ms 2944 KB answer = YES
55 Correct 6 ms 3120 KB answer = YES
56 Correct 11 ms 3456 KB answer = YES
57 Correct 9 ms 3328 KB answer = YES
58 Correct 8 ms 3328 KB answer = YES
59 Correct 10 ms 3328 KB answer = YES
60 Correct 9 ms 3456 KB answer = YES
61 Correct 6 ms 3072 KB answer = YES
62 Correct 100 ms 10104 KB answer = NO
63 Correct 104 ms 10232 KB answer = YES
64 Correct 107 ms 10104 KB answer = NO
65 Correct 108 ms 10232 KB answer = YES
66 Correct 4 ms 2816 KB answer = YES
67 Correct 71 ms 14836 KB answer = YES
68 Correct 68 ms 14696 KB answer = YES
69 Correct 71 ms 14324 KB answer = YES
70 Correct 133 ms 18792 KB answer = YES
71 Correct 66 ms 14300 KB answer = YES
72 Correct 116 ms 10780 KB answer = YES
73 Correct 124 ms 10276 KB answer = YES
74 Correct 56 ms 9728 KB answer = YES
75 Correct 58 ms 9084 KB answer = NO
76 Correct 15 ms 3712 KB answer = YES
77 Correct 33 ms 4728 KB answer = YES
78 Correct 38 ms 6132 KB answer = YES
79 Correct 92 ms 9452 KB answer = YES
80 Correct 72 ms 10000 KB answer = YES
81 Correct 81 ms 11340 KB answer = NO
82 Correct 97 ms 14052 KB answer = YES
83 Correct 111 ms 14580 KB answer = YES
84 Correct 123 ms 14836 KB answer = YES
85 Correct 134 ms 14836 KB answer = YES
86 Correct 70 ms 14452 KB answer = YES
87 Correct 86 ms 10232 KB answer = NO
88 Correct 133 ms 11560 KB answer = YES
89 Correct 97 ms 9128 KB answer = YES
90 Correct 107 ms 9080 KB answer = YES
91 Correct 105 ms 9080 KB answer = YES
92 Correct 58 ms 6512 KB answer = YES
93 Correct 52 ms 6584 KB answer = YES
94 Correct 111 ms 13556 KB answer = NO
95 Correct 77 ms 8708 KB answer = NO
96 Correct 231 ms 16936 KB answer = YES
97 Correct 57 ms 13556 KB answer = NO