답안 #650539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650539 2022-10-14T08:02:47 Z DJeniUp Graph (BOI20_graph) C++17
100 / 100
293 ms 30268 KB
#include "bits/stdc++.h"
//#pragma GCC optimize("O3")
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef long double ld;
 
#define fr first
#define sc second
#define pb push_back
#define INF 100000000007
#define endl '\n'
#define MOD 998244353
#define A 31
#define N 100007
#define eps 0.000000000001
 
ll n,m,a[N],b[N],f[N];

ld res[N];

vector<pairll>v[N];

vector<ll>num;

ld S(ll x,ll a1,ll b1,ll y){
    if(f[x]==1 && a[x]!=a1){
        return ld(b1-b[x])/ld(a[x]-a1);
    }else if(f[x]==1 && b[x]!=b1)return -INF;
    else if(f[x]==1)return INF;
    num.pb(x);
    f[x]=1;
    a[x]=a1;
    b[x]=b1;
    for(int i=0;i<v[x].size();i++){
        if(v[x][i].fr!=y){
            ld r=S(v[x][i].fr,0-a1,v[x][i].sc-b1,x);
            if(r!=INF)return r;
        }
    }
    return INF;
}

ll D(ll x,ll y,ld a1){
    f[x]=2;
    res[x]=a1;
    for(auto it:v[x]){
        if(it.fr!=y){
            if(f[it.fr]==2){
                if(abs(a1+res[it.fr]-ld(it.sc))>eps)return 1;
            }else{
                ll r=D(it.fr,x,ld(it.sc)-a1);
                if(r==1)return 1;
            }
        }
    }
    return 0;
}

int main(){
    
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        ll x,y,z;
        cin>>x>>y>>z;
        v[x].pb({y,z});
        v[y].pb({x,z});
    }
    for(int i=1;i<=n;i++){
        if(f[i]==0){
            num.clear();
            ld x=S(i,1,0,0);
            if(x==-INF){
                cout<<"NO"<<endl;
                return 0;
            }else if(x==INF){
                ld l=-100;
                ld r=100;
                ld r1=0;
                ld r2=0;
                while(r-l>eps){
                    ld m1=(l+(r-l)/3.0);
                    ld m2=(r-(r-l)/3.0);
                    r1=0;
                    r2=0;
                    for(auto j:num){
                        r1+=abs(m1*ld(a[j])+ld(b[j]));
                        r2+=abs(m2*ld(a[j])+ld(b[j]));
                    }
                    if(r1<r2)r=m2;
                    else l=m1;
                }
                for(auto j:num){
                    res[j]=l*ld(a[j])+ld(b[j]);
                }
            }else{
                ll r=D(i,0,x);
                if(r==1){
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"YES"<<endl;
    for(int i=1;i<=n;i++){
        cout<<fixed<<setprecision(10)<<res[i]<<" ";
    }
    cout<<endl;
    
    return 0;
}

Compilation message

Graph.cpp: In function 'ld S(ll, ll, ll, ll)':
Graph.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2680 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2680 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2564 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2680 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2564 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 3 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 3 ms 2772 KB answer = YES
43 Correct 3 ms 2772 KB answer = YES
44 Correct 3 ms 2772 KB answer = YES
45 Correct 3 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 3 ms 2772 KB answer = YES
48 Correct 3 ms 2772 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2680 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2564 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 3 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 3 ms 2772 KB answer = YES
43 Correct 3 ms 2772 KB answer = YES
44 Correct 3 ms 2772 KB answer = YES
45 Correct 3 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 3 ms 2772 KB answer = YES
48 Correct 3 ms 2772 KB answer = YES
49 Correct 16 ms 3924 KB answer = YES
50 Correct 15 ms 4308 KB answer = YES
51 Correct 17 ms 4192 KB answer = YES
52 Correct 8 ms 3440 KB answer = NO
53 Correct 3 ms 2772 KB answer = YES
54 Correct 6 ms 2900 KB answer = YES
55 Correct 9 ms 3284 KB answer = YES
56 Correct 16 ms 3796 KB answer = YES
57 Correct 17 ms 3652 KB answer = YES
58 Correct 15 ms 3644 KB answer = YES
59 Correct 14 ms 3604 KB answer = YES
60 Correct 18 ms 3796 KB answer = YES
61 Correct 8 ms 3284 KB answer = YES
62 Correct 131 ms 12040 KB answer = NO
63 Correct 138 ms 12668 KB answer = YES
64 Correct 140 ms 12748 KB answer = NO
65 Correct 148 ms 12688 KB answer = YES
66 Correct 5 ms 2900 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB answer = YES
2 Correct 1 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2644 KB answer = NO
5 Correct 1 ms 2644 KB answer = YES
6 Correct 2 ms 2644 KB answer = YES
7 Correct 2 ms 2644 KB answer = YES
8 Correct 2 ms 2644 KB answer = YES
9 Correct 1 ms 2680 KB answer = NO
10 Correct 1 ms 2644 KB answer = YES
11 Correct 2 ms 2644 KB answer = YES
12 Correct 2 ms 2644 KB answer = NO
13 Correct 2 ms 2644 KB answer = YES
14 Correct 1 ms 2644 KB answer = YES
15 Correct 2 ms 2644 KB answer = YES
16 Correct 2 ms 2644 KB answer = YES
17 Correct 1 ms 2644 KB answer = YES
18 Correct 2 ms 2644 KB answer = YES
19 Correct 1 ms 2644 KB answer = YES
20 Correct 2 ms 2644 KB answer = YES
21 Correct 1 ms 2644 KB answer = YES
22 Correct 1 ms 2644 KB answer = NO
23 Correct 1 ms 2644 KB answer = NO
24 Correct 2 ms 2644 KB answer = YES
25 Correct 2 ms 2644 KB answer = YES
26 Correct 2 ms 2644 KB answer = YES
27 Correct 2 ms 2644 KB answer = YES
28 Correct 2 ms 2644 KB answer = YES
29 Correct 2 ms 2644 KB answer = YES
30 Correct 2 ms 2564 KB answer = NO
31 Correct 2 ms 2644 KB answer = YES
32 Correct 2 ms 2644 KB answer = YES
33 Correct 2 ms 2644 KB answer = YES
34 Correct 2 ms 2644 KB answer = YES
35 Correct 2 ms 2644 KB answer = YES
36 Correct 2 ms 2644 KB answer = YES
37 Correct 2 ms 2644 KB answer = YES
38 Correct 2 ms 2644 KB answer = YES
39 Correct 2 ms 2644 KB answer = YES
40 Correct 3 ms 2772 KB answer = YES
41 Correct 2 ms 2644 KB answer = NO
42 Correct 3 ms 2772 KB answer = YES
43 Correct 3 ms 2772 KB answer = YES
44 Correct 3 ms 2772 KB answer = YES
45 Correct 3 ms 2772 KB answer = YES
46 Correct 2 ms 2644 KB answer = YES
47 Correct 3 ms 2772 KB answer = YES
48 Correct 3 ms 2772 KB answer = YES
49 Correct 16 ms 3924 KB answer = YES
50 Correct 15 ms 4308 KB answer = YES
51 Correct 17 ms 4192 KB answer = YES
52 Correct 8 ms 3440 KB answer = NO
53 Correct 3 ms 2772 KB answer = YES
54 Correct 6 ms 2900 KB answer = YES
55 Correct 9 ms 3284 KB answer = YES
56 Correct 16 ms 3796 KB answer = YES
57 Correct 17 ms 3652 KB answer = YES
58 Correct 15 ms 3644 KB answer = YES
59 Correct 14 ms 3604 KB answer = YES
60 Correct 18 ms 3796 KB answer = YES
61 Correct 8 ms 3284 KB answer = YES
62 Correct 131 ms 12040 KB answer = NO
63 Correct 138 ms 12668 KB answer = YES
64 Correct 140 ms 12748 KB answer = NO
65 Correct 148 ms 12688 KB answer = YES
66 Correct 5 ms 2900 KB answer = YES
67 Correct 171 ms 19828 KB answer = YES
68 Correct 162 ms 20976 KB answer = YES
69 Correct 135 ms 22644 KB answer = YES
70 Correct 211 ms 30268 KB answer = YES
71 Correct 139 ms 22596 KB answer = YES
72 Correct 181 ms 15292 KB answer = YES
73 Correct 175 ms 14752 KB answer = YES
74 Correct 115 ms 14408 KB answer = YES
75 Correct 58 ms 10044 KB answer = NO
76 Correct 22 ms 4140 KB answer = YES
77 Correct 42 ms 5744 KB answer = YES
78 Correct 79 ms 8140 KB answer = YES
79 Correct 159 ms 13364 KB answer = YES
80 Correct 126 ms 13868 KB answer = YES
81 Correct 104 ms 17120 KB answer = NO
82 Correct 177 ms 21668 KB answer = YES
83 Correct 201 ms 23316 KB answer = YES
84 Correct 224 ms 21608 KB answer = YES
85 Correct 169 ms 21084 KB answer = YES
86 Correct 163 ms 22664 KB answer = YES
87 Correct 130 ms 15204 KB answer = NO
88 Correct 199 ms 18272 KB answer = YES
89 Correct 185 ms 13868 KB answer = YES
90 Correct 164 ms 13852 KB answer = YES
91 Correct 173 ms 14412 KB answer = YES
92 Correct 75 ms 8768 KB answer = YES
93 Correct 69 ms 8712 KB answer = YES
94 Correct 112 ms 18692 KB answer = NO
95 Correct 99 ms 12996 KB answer = NO
96 Correct 293 ms 25620 KB answer = YES
97 Correct 89 ms 18116 KB answer = NO