Submission #661022

# Submission time Handle Problem Language Result Execution time Memory
661022 2022-11-23T23:00:21 Z ktkerem Graph (BOI20_graph) C++17
100 / 100
183 ms 30736 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e14 + 7; 
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<ll> ar(ous) , vis(ous) , svis(ous) , sgn(ous) , val(ous) , kp ;ll cyc = 0;std::vector<long double> ans(ous);
std::vector<llll> adj[ous];
long double oo;
void dfs(ll crt){
    vis[crt] = 1;
    for(auto j:adj[crt]){
        if(vis[j.fi] == 0){
            sgn[j.fi] = -sgn[crt];
            val[j.fi] = j.sec - val[crt];
            kp.pb((-sgn[j.fi])*val[j.fi]);
            dfs(j.fi);
        }
        else if(sgn[crt] == sgn[j.fi]){
            cyc = 1;
            oo = sgn[j.fi]*(j.sec - val[j.fi] - val[crt])/2.0;
        }
    }
}
ll ctdfs(ll crt){
    svis[crt] = 1;
    for(auto j:adj[crt]){
        ans[j.fi] = sgn[j.fi] * oo + val[j.fi];
        if(ans[j.fi] + ans[crt] != j.sec){
            return 0;
        }
    }
    for(auto j:adj[crt]){
        if(svis[j.fi] == 0 && ctdfs(j.fi) == 0){
            return 0;
        }
    }
    return 1;
}
void solve(){
    std::cin >> n >> m;
    for(ll i = 0;m>i;i++){
        ll x , y , z;std::cin >> x >> y >> z;
        adj[x].pb({y , z});
        adj[y].pb({x , z});
    }
    for(ll i = 1;n>=i;i++){
        if(vis[i] == 0){
            kp.clear();
            cyc = 0;
            oo = 0;
            vis[i] = 1;sgn[i] = 1;val[i] = 0;
            kp.pb((-sgn[i])*val[i]);
            dfs(i);
            if(cyc == 0){
                std::sort(all(kp));
                oo = kp[kp.size() / 2];
            }
            ans[i] = sgn[i] * oo + val[i];
            //std::cout << ans[i] << " " << oo << " " << cyc << "\n";
            if(ctdfs(i) == 0){
                std::cout << "NO\n";
                return;
            }
        }
    }
    std::cout << "YES\n";
    for(ll i = 1;n>=i;i++){
        std::cout << ans[i]  << " ";
    }
    return;/**/
}
signed main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    ll t=1;
    //std::cin >> t;
    ll o = 1;
    while(t--){ 
        //cout << "Case " << o++ << ":\n";
        solve();
    }
    return 0;
}/**/

Compilation message

Graph.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
Graph.cpp: In function 'int main()':
Graph.cpp:94:8: warning: unused variable 'o' [-Wunused-variable]
   94 |     ll o = 1;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB answer = YES
2 Correct 5 ms 8176 KB answer = YES
3 Correct 5 ms 8168 KB answer = YES
4 Correct 6 ms 8148 KB answer = NO
5 Correct 4 ms 8112 KB answer = YES
6 Correct 4 ms 8148 KB answer = YES
7 Correct 4 ms 8148 KB answer = YES
8 Correct 5 ms 8060 KB answer = YES
9 Correct 5 ms 8148 KB answer = NO
10 Correct 4 ms 8148 KB answer = YES
11 Correct 4 ms 8148 KB answer = YES
12 Correct 5 ms 8148 KB answer = NO
13 Correct 5 ms 8148 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8148 KB answer = YES
16 Correct 4 ms 8148 KB answer = YES
17 Correct 4 ms 8148 KB answer = YES
18 Correct 4 ms 8148 KB answer = YES
19 Correct 5 ms 8276 KB answer = YES
20 Correct 4 ms 8148 KB answer = YES
21 Correct 4 ms 8148 KB answer = YES
22 Correct 4 ms 8148 KB answer = NO
23 Correct 4 ms 8148 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB answer = YES
2 Correct 5 ms 8176 KB answer = YES
3 Correct 5 ms 8168 KB answer = YES
4 Correct 6 ms 8148 KB answer = NO
5 Correct 4 ms 8112 KB answer = YES
6 Correct 4 ms 8148 KB answer = YES
7 Correct 4 ms 8148 KB answer = YES
8 Correct 5 ms 8060 KB answer = YES
9 Correct 5 ms 8148 KB answer = NO
10 Correct 4 ms 8148 KB answer = YES
11 Correct 4 ms 8148 KB answer = YES
12 Correct 5 ms 8148 KB answer = NO
13 Correct 5 ms 8148 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8148 KB answer = YES
16 Correct 4 ms 8148 KB answer = YES
17 Correct 4 ms 8148 KB answer = YES
18 Correct 4 ms 8148 KB answer = YES
19 Correct 5 ms 8276 KB answer = YES
20 Correct 4 ms 8148 KB answer = YES
21 Correct 4 ms 8148 KB answer = YES
22 Correct 4 ms 8148 KB answer = NO
23 Correct 4 ms 8148 KB answer = NO
24 Correct 4 ms 8120 KB answer = YES
25 Correct 4 ms 8184 KB answer = YES
26 Correct 4 ms 8180 KB answer = YES
27 Correct 4 ms 8176 KB answer = YES
28 Correct 4 ms 8148 KB answer = YES
29 Correct 4 ms 8148 KB answer = YES
30 Correct 4 ms 8148 KB answer = NO
31 Correct 4 ms 8148 KB answer = YES
32 Correct 4 ms 8148 KB answer = YES
33 Correct 4 ms 8148 KB answer = YES
34 Correct 4 ms 8148 KB answer = YES
35 Correct 4 ms 8148 KB answer = YES
36 Correct 4 ms 8172 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB answer = YES
2 Correct 5 ms 8176 KB answer = YES
3 Correct 5 ms 8168 KB answer = YES
4 Correct 6 ms 8148 KB answer = NO
5 Correct 4 ms 8112 KB answer = YES
6 Correct 4 ms 8148 KB answer = YES
7 Correct 4 ms 8148 KB answer = YES
8 Correct 5 ms 8060 KB answer = YES
9 Correct 5 ms 8148 KB answer = NO
10 Correct 4 ms 8148 KB answer = YES
11 Correct 4 ms 8148 KB answer = YES
12 Correct 5 ms 8148 KB answer = NO
13 Correct 5 ms 8148 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8148 KB answer = YES
16 Correct 4 ms 8148 KB answer = YES
17 Correct 4 ms 8148 KB answer = YES
18 Correct 4 ms 8148 KB answer = YES
19 Correct 5 ms 8276 KB answer = YES
20 Correct 4 ms 8148 KB answer = YES
21 Correct 4 ms 8148 KB answer = YES
22 Correct 4 ms 8148 KB answer = NO
23 Correct 4 ms 8148 KB answer = NO
24 Correct 4 ms 8120 KB answer = YES
25 Correct 4 ms 8184 KB answer = YES
26 Correct 4 ms 8180 KB answer = YES
27 Correct 4 ms 8176 KB answer = YES
28 Correct 4 ms 8148 KB answer = YES
29 Correct 4 ms 8148 KB answer = YES
30 Correct 4 ms 8148 KB answer = NO
31 Correct 4 ms 8148 KB answer = YES
32 Correct 4 ms 8148 KB answer = YES
33 Correct 4 ms 8148 KB answer = YES
34 Correct 4 ms 8148 KB answer = YES
35 Correct 4 ms 8148 KB answer = YES
36 Correct 4 ms 8172 KB answer = YES
37 Correct 4 ms 8148 KB answer = YES
38 Correct 5 ms 8148 KB answer = YES
39 Correct 4 ms 8184 KB answer = YES
40 Correct 4 ms 8148 KB answer = YES
41 Correct 4 ms 8148 KB answer = NO
42 Correct 4 ms 8148 KB answer = YES
43 Correct 4 ms 8188 KB answer = YES
44 Correct 5 ms 8148 KB answer = YES
45 Correct 4 ms 8180 KB answer = YES
46 Correct 4 ms 8180 KB answer = YES
47 Correct 5 ms 8148 KB answer = YES
48 Correct 6 ms 8148 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB answer = YES
2 Correct 5 ms 8176 KB answer = YES
3 Correct 5 ms 8168 KB answer = YES
4 Correct 6 ms 8148 KB answer = NO
5 Correct 4 ms 8112 KB answer = YES
6 Correct 4 ms 8148 KB answer = YES
7 Correct 4 ms 8148 KB answer = YES
8 Correct 5 ms 8060 KB answer = YES
9 Correct 5 ms 8148 KB answer = NO
10 Correct 4 ms 8148 KB answer = YES
11 Correct 4 ms 8148 KB answer = YES
12 Correct 5 ms 8148 KB answer = NO
13 Correct 5 ms 8148 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8148 KB answer = YES
16 Correct 4 ms 8148 KB answer = YES
17 Correct 4 ms 8148 KB answer = YES
18 Correct 4 ms 8148 KB answer = YES
19 Correct 5 ms 8276 KB answer = YES
20 Correct 4 ms 8148 KB answer = YES
21 Correct 4 ms 8148 KB answer = YES
22 Correct 4 ms 8148 KB answer = NO
23 Correct 4 ms 8148 KB answer = NO
24 Correct 4 ms 8120 KB answer = YES
25 Correct 4 ms 8184 KB answer = YES
26 Correct 4 ms 8180 KB answer = YES
27 Correct 4 ms 8176 KB answer = YES
28 Correct 4 ms 8148 KB answer = YES
29 Correct 4 ms 8148 KB answer = YES
30 Correct 4 ms 8148 KB answer = NO
31 Correct 4 ms 8148 KB answer = YES
32 Correct 4 ms 8148 KB answer = YES
33 Correct 4 ms 8148 KB answer = YES
34 Correct 4 ms 8148 KB answer = YES
35 Correct 4 ms 8148 KB answer = YES
36 Correct 4 ms 8172 KB answer = YES
37 Correct 4 ms 8148 KB answer = YES
38 Correct 5 ms 8148 KB answer = YES
39 Correct 4 ms 8184 KB answer = YES
40 Correct 4 ms 8148 KB answer = YES
41 Correct 4 ms 8148 KB answer = NO
42 Correct 4 ms 8148 KB answer = YES
43 Correct 4 ms 8188 KB answer = YES
44 Correct 5 ms 8148 KB answer = YES
45 Correct 4 ms 8180 KB answer = YES
46 Correct 4 ms 8180 KB answer = YES
47 Correct 5 ms 8148 KB answer = YES
48 Correct 6 ms 8148 KB answer = YES
49 Correct 12 ms 8960 KB answer = YES
50 Correct 12 ms 9428 KB answer = YES
51 Correct 11 ms 9428 KB answer = YES
52 Correct 7 ms 9336 KB answer = NO
53 Correct 4 ms 8148 KB answer = YES
54 Correct 5 ms 8312 KB answer = YES
55 Correct 7 ms 8576 KB answer = YES
56 Correct 13 ms 8968 KB answer = YES
57 Correct 11 ms 8788 KB answer = YES
58 Correct 10 ms 8828 KB answer = YES
59 Correct 10 ms 8788 KB answer = YES
60 Correct 11 ms 8916 KB answer = YES
61 Correct 8 ms 8532 KB answer = YES
62 Correct 61 ms 20236 KB answer = NO
63 Correct 63 ms 20300 KB answer = YES
64 Correct 61 ms 20280 KB answer = NO
65 Correct 64 ms 20260 KB answer = YES
66 Correct 7 ms 8276 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB answer = YES
2 Correct 5 ms 8176 KB answer = YES
3 Correct 5 ms 8168 KB answer = YES
4 Correct 6 ms 8148 KB answer = NO
5 Correct 4 ms 8112 KB answer = YES
6 Correct 4 ms 8148 KB answer = YES
7 Correct 4 ms 8148 KB answer = YES
8 Correct 5 ms 8060 KB answer = YES
9 Correct 5 ms 8148 KB answer = NO
10 Correct 4 ms 8148 KB answer = YES
11 Correct 4 ms 8148 KB answer = YES
12 Correct 5 ms 8148 KB answer = NO
13 Correct 5 ms 8148 KB answer = YES
14 Correct 5 ms 8172 KB answer = YES
15 Correct 5 ms 8148 KB answer = YES
16 Correct 4 ms 8148 KB answer = YES
17 Correct 4 ms 8148 KB answer = YES
18 Correct 4 ms 8148 KB answer = YES
19 Correct 5 ms 8276 KB answer = YES
20 Correct 4 ms 8148 KB answer = YES
21 Correct 4 ms 8148 KB answer = YES
22 Correct 4 ms 8148 KB answer = NO
23 Correct 4 ms 8148 KB answer = NO
24 Correct 4 ms 8120 KB answer = YES
25 Correct 4 ms 8184 KB answer = YES
26 Correct 4 ms 8180 KB answer = YES
27 Correct 4 ms 8176 KB answer = YES
28 Correct 4 ms 8148 KB answer = YES
29 Correct 4 ms 8148 KB answer = YES
30 Correct 4 ms 8148 KB answer = NO
31 Correct 4 ms 8148 KB answer = YES
32 Correct 4 ms 8148 KB answer = YES
33 Correct 4 ms 8148 KB answer = YES
34 Correct 4 ms 8148 KB answer = YES
35 Correct 4 ms 8148 KB answer = YES
36 Correct 4 ms 8172 KB answer = YES
37 Correct 4 ms 8148 KB answer = YES
38 Correct 5 ms 8148 KB answer = YES
39 Correct 4 ms 8184 KB answer = YES
40 Correct 4 ms 8148 KB answer = YES
41 Correct 4 ms 8148 KB answer = NO
42 Correct 4 ms 8148 KB answer = YES
43 Correct 4 ms 8188 KB answer = YES
44 Correct 5 ms 8148 KB answer = YES
45 Correct 4 ms 8180 KB answer = YES
46 Correct 4 ms 8180 KB answer = YES
47 Correct 5 ms 8148 KB answer = YES
48 Correct 6 ms 8148 KB answer = YES
49 Correct 12 ms 8960 KB answer = YES
50 Correct 12 ms 9428 KB answer = YES
51 Correct 11 ms 9428 KB answer = YES
52 Correct 7 ms 9336 KB answer = NO
53 Correct 4 ms 8148 KB answer = YES
54 Correct 5 ms 8312 KB answer = YES
55 Correct 7 ms 8576 KB answer = YES
56 Correct 13 ms 8968 KB answer = YES
57 Correct 11 ms 8788 KB answer = YES
58 Correct 10 ms 8828 KB answer = YES
59 Correct 10 ms 8788 KB answer = YES
60 Correct 11 ms 8916 KB answer = YES
61 Correct 8 ms 8532 KB answer = YES
62 Correct 61 ms 20236 KB answer = NO
63 Correct 63 ms 20300 KB answer = YES
64 Correct 61 ms 20280 KB answer = NO
65 Correct 64 ms 20260 KB answer = YES
66 Correct 7 ms 8276 KB answer = YES
67 Correct 80 ms 23260 KB answer = YES
68 Correct 78 ms 23072 KB answer = YES
69 Correct 75 ms 23116 KB answer = YES
70 Correct 118 ms 30736 KB answer = YES
71 Correct 81 ms 23356 KB answer = YES
72 Correct 104 ms 15768 KB answer = YES
73 Correct 114 ms 15816 KB answer = YES
74 Correct 59 ms 16896 KB answer = YES
75 Correct 33 ms 16712 KB answer = NO
76 Correct 13 ms 9080 KB answer = YES
77 Correct 24 ms 10116 KB answer = YES
78 Correct 39 ms 11484 KB answer = YES
79 Correct 85 ms 14824 KB answer = YES
80 Correct 62 ms 16880 KB answer = YES
81 Correct 44 ms 19200 KB answer = NO
82 Correct 96 ms 22724 KB answer = YES
83 Correct 117 ms 23820 KB answer = YES
84 Correct 121 ms 23824 KB answer = YES
85 Correct 82 ms 23216 KB answer = YES
86 Correct 76 ms 23152 KB answer = YES
87 Correct 55 ms 17344 KB answer = NO
88 Correct 123 ms 18888 KB answer = YES
89 Correct 87 ms 14412 KB answer = YES
90 Correct 86 ms 14448 KB answer = YES
91 Correct 104 ms 15020 KB answer = YES
92 Correct 45 ms 12088 KB answer = YES
93 Correct 43 ms 12040 KB answer = YES
94 Correct 62 ms 23484 KB answer = NO
95 Correct 43 ms 14740 KB answer = NO
96 Correct 183 ms 27204 KB answer = YES
97 Correct 38 ms 22848 KB answer = NO