Submission #254803

# Submission time Handle Problem Language Result Execution time Memory
254803 2020-07-30T15:46:04 Z 2fat2code Graph (BOI20_graph) C++17
100 / 100
375 ms 23956 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;
 
const int nmax = 100005;
const long double eps = 1e-12;
 
long double ans[nmax];
int n,m;
 
struct varf{
    int coef,cons;
}arr[nmax];
 
int AAA = 0;
long double tz = 0;
 
vector<pair<int,int>>nod[nmax];
vector<int>vecc;
bitset<nmax>viz;
bitset<nmax>viz2;
 
void DFS(int s){
    vecc.push_back(s);
    viz[s] = 1;
    for(auto it : nod[s]){
        if(!viz[it.fr]){
            arr[it.fr].coef = -arr[s].coef;
            if(it.sc == 1LL){
                arr[it.fr].cons = 1LL - arr[s].cons;
            }
            else{
                arr[it.fr].cons = 2LL - arr[s].cons;
            }
            DFS(it.fr);
        }
        else{
            int currcons = 0LL;
            if(it.sc == 1LL){
                currcons = 1LL - arr[s].cons;
            }
            else{
                currcons = 2LL - arr[s].cons;
            }
            int currcoef = -arr[s].coef;
            if(arr[it.fr].coef == currcoef && arr[it.fr].cons != currcons){
                rcc("NO");
            }
            else if(currcoef != arr[it.fr].coef){
                AAA = 1;
                tz = (long double)(arr[it.fr].cons - currcons)/(currcoef - arr[it.fr].coef);
            }
        }
    }
}
 
void check(int l,int r,int val){
    long double lmao = (long double) (arr[l].coef * tz + arr[l].cons);
    lmao += (long double) (arr[r].coef * tz + arr[r].cons);
    lmao = (long double) (lmao - val);
    if(abs(lmao) >= eps){
        rcc("NO");
    }
}
 
map<int,int>q;
 
void CHECK12(int s){
    viz2[s] = 1;
    for(auto it : nod[s]){
        check(it.fr,s,it.sc);
        if(!viz2[it.fr]){
            CHECK12(it.fr);
        }
    }
}
 
int32_t main(){
    cout << fixed << setprecision(13);
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        int x,y,z;
        cin >> x >> y >> z;
        nod[x].push_back({y,z});
        nod[y].push_back({x,z});
    }
    for(int i=1;i<=n;i++){
        if(viz[i] == 0){
            AAA = 0;
            arr[i].cons = 0;
            arr[i].coef = 1;
            vecc.clear();
            DFS(i);
            if(AAA == 1){
                CHECK12(i);
                for(auto it : vecc){
                    ans[it] = (long double)arr[it].coef * tz + arr[it].cons;
                }
            }
            else{
                q.clear();
                for(auto it : vecc){
                    if(arr[it].coef < 0LL){
                        q[arr[it].cons]++;
                    }
                    else{
                        q[-arr[it].cons]++;
                    }
                }
                auto it = q.begin();
                int nec = ((int)vecc.size() + 1)/2;
                int curr = (it->sc);
                int anslmao = 0;
                while(true){
                    if(curr >= nec){
                        anslmao = (it->fr);
                        break;
                    }
                    it++;
                    if(it == q.end()){
                        break;
                    }
                    else{
                        curr += (it->sc);
                    }
                }
                for(auto it : vecc){
                    ans[it] = anslmao * arr[it].coef + arr[it].cons;
                }
            }
        }
    }
    cout << "YES" << '\n';
    for(int i=1;i<=n;i++) cout << ans[i] << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 1 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 1 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 1 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 1 ms 2688 KB answer = YES
11 Correct 2 ms 2688 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 2816 KB answer = YES
19 Correct 1 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 1 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 1 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 1 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 1 ms 2688 KB answer = YES
11 Correct 2 ms 2688 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 2816 KB answer = YES
19 Correct 1 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 1 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 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 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 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 1 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 1 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 1 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 1 ms 2688 KB answer = YES
11 Correct 2 ms 2688 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 2816 KB answer = YES
19 Correct 1 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 1 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 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 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 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 2688 KB answer = YES
39 Correct 3 ms 2688 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 2 ms 2816 KB answer = NO
42 Correct 4 ms 2816 KB answer = YES
43 Correct 4 ms 2816 KB answer = YES
44 Correct 4 ms 2816 KB answer = YES
45 Correct 4 ms 2816 KB answer = YES
46 Correct 3 ms 2688 KB answer = YES
47 Correct 4 ms 2816 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 1 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 1 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 1 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 1 ms 2688 KB answer = YES
11 Correct 2 ms 2688 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 2816 KB answer = YES
19 Correct 1 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 1 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 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 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 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 2688 KB answer = YES
39 Correct 3 ms 2688 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 2 ms 2816 KB answer = NO
42 Correct 4 ms 2816 KB answer = YES
43 Correct 4 ms 2816 KB answer = YES
44 Correct 4 ms 2816 KB answer = YES
45 Correct 4 ms 2816 KB answer = YES
46 Correct 3 ms 2688 KB answer = YES
47 Correct 4 ms 2816 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
49 Correct 19 ms 3840 KB answer = YES
50 Correct 20 ms 4096 KB answer = YES
51 Correct 19 ms 4088 KB answer = YES
52 Correct 13 ms 3328 KB answer = NO
53 Correct 3 ms 2816 KB answer = YES
54 Correct 6 ms 2944 KB answer = YES
55 Correct 10 ms 3328 KB answer = YES
56 Correct 18 ms 3840 KB answer = YES
57 Correct 18 ms 3712 KB answer = YES
58 Correct 17 ms 3712 KB answer = YES
59 Correct 18 ms 3712 KB answer = YES
60 Correct 27 ms 3840 KB answer = YES
61 Correct 11 ms 3328 KB answer = YES
62 Correct 228 ms 12024 KB answer = NO
63 Correct 228 ms 12664 KB answer = YES
64 Correct 220 ms 12408 KB answer = NO
65 Correct 231 ms 12660 KB answer = YES
66 Correct 5 ms 2944 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB answer = YES
2 Correct 1 ms 2688 KB answer = YES
3 Correct 2 ms 2688 KB answer = YES
4 Correct 1 ms 2688 KB answer = NO
5 Correct 2 ms 2688 KB answer = YES
6 Correct 1 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 1 ms 2688 KB answer = YES
11 Correct 2 ms 2688 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 2816 KB answer = YES
19 Correct 1 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 1 ms 2688 KB answer = YES
25 Correct 2 ms 2688 KB answer = YES
26 Correct 2 ms 2688 KB answer = YES
27 Correct 2 ms 2688 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 2 ms 2688 KB answer = YES
33 Correct 2 ms 2688 KB answer = YES
34 Correct 2 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 2688 KB answer = YES
39 Correct 3 ms 2688 KB answer = YES
40 Correct 3 ms 2816 KB answer = YES
41 Correct 2 ms 2816 KB answer = NO
42 Correct 4 ms 2816 KB answer = YES
43 Correct 4 ms 2816 KB answer = YES
44 Correct 4 ms 2816 KB answer = YES
45 Correct 4 ms 2816 KB answer = YES
46 Correct 3 ms 2688 KB answer = YES
47 Correct 4 ms 2816 KB answer = YES
48 Correct 3 ms 2816 KB answer = YES
49 Correct 19 ms 3840 KB answer = YES
50 Correct 20 ms 4096 KB answer = YES
51 Correct 19 ms 4088 KB answer = YES
52 Correct 13 ms 3328 KB answer = NO
53 Correct 3 ms 2816 KB answer = YES
54 Correct 6 ms 2944 KB answer = YES
55 Correct 10 ms 3328 KB answer = YES
56 Correct 18 ms 3840 KB answer = YES
57 Correct 18 ms 3712 KB answer = YES
58 Correct 17 ms 3712 KB answer = YES
59 Correct 18 ms 3712 KB answer = YES
60 Correct 27 ms 3840 KB answer = YES
61 Correct 11 ms 3328 KB answer = YES
62 Correct 228 ms 12024 KB answer = NO
63 Correct 228 ms 12664 KB answer = YES
64 Correct 220 ms 12408 KB answer = NO
65 Correct 231 ms 12660 KB answer = YES
66 Correct 5 ms 2944 KB answer = YES
67 Correct 188 ms 17904 KB answer = YES
68 Correct 177 ms 17776 KB answer = YES
69 Correct 177 ms 17776 KB answer = YES
70 Correct 313 ms 23956 KB answer = YES
71 Correct 178 ms 17776 KB answer = YES
72 Correct 195 ms 13552 KB answer = YES
73 Correct 199 ms 13552 KB answer = YES
74 Correct 133 ms 11964 KB answer = YES
75 Correct 79 ms 8312 KB answer = NO
76 Correct 22 ms 4096 KB answer = YES
77 Correct 46 ms 5500 KB answer = YES
78 Correct 78 ms 7408 KB answer = YES
79 Correct 166 ms 11884 KB answer = YES
80 Correct 128 ms 12016 KB answer = YES
81 Correct 129 ms 12204 KB answer = NO
82 Correct 211 ms 17424 KB answer = YES
83 Correct 236 ms 18412 KB answer = YES
84 Correct 286 ms 18412 KB answer = YES
85 Correct 192 ms 18032 KB answer = YES
86 Correct 208 ms 17900 KB answer = YES
87 Correct 138 ms 12672 KB answer = NO
88 Correct 279 ms 15216 KB answer = YES
89 Correct 216 ms 12152 KB answer = YES
90 Correct 195 ms 12156 KB answer = YES
91 Correct 220 ms 12664 KB answer = YES
92 Correct 102 ms 8180 KB answer = YES
93 Correct 101 ms 8180 KB answer = YES
94 Correct 156 ms 15084 KB answer = NO
95 Correct 133 ms 11000 KB answer = NO
96 Correct 375 ms 21488 KB answer = YES
97 Correct 119 ms 14576 KB answer = NO