제출 #650537

#제출 시각아이디문제언어결과실행 시간메모리
650537DJeniUpGraph (BOI20_graph)C++17
58 / 100
158 ms21180 KiB
#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.0000000001 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; }

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...