Submission #650535

# Submission time Handle Problem Language Result Execution time Memory
650535 2022-10-14T08:00:52 Z DJeniUp Graph (BOI20_graph) C++17
0 / 100
3 ms 2656 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.00000001
 
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;
            }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++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 3 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2600 KB answer = NO
5 Correct 2 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 Incorrect 2 ms 2656 KB Extra information in the output file
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 3 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2600 KB answer = NO
5 Correct 2 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 Incorrect 2 ms 2656 KB Extra information in the output file
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 3 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2600 KB answer = NO
5 Correct 2 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 Incorrect 2 ms 2656 KB Extra information in the output file
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 3 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2600 KB answer = NO
5 Correct 2 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 Incorrect 2 ms 2656 KB Extra information in the output file
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB answer = YES
2 Correct 3 ms 2644 KB answer = YES
3 Correct 2 ms 2644 KB answer = YES
4 Correct 2 ms 2600 KB answer = NO
5 Correct 2 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 Incorrect 2 ms 2656 KB Extra information in the output file
10 Halted 0 ms 0 KB -