Submission #1107944

#TimeUsernameProblemLanguageResultExecution timeMemory
1107944simona1230Graph (BOI20_graph)C++17
0 / 100
2 ms3664 KiB
#include <bits/stdc++.h> using namespace std; int n,m; vector<pair<int,double> > v[100001]; void read() { cin>>n>>m; for(int i=1; i<=m; i++) { int a,b,c; cin>>a>>b>>c; v[a].push_back({b,c}); v[b].push_back({a,c}); } } vector<int> curr; double sum,ans; int pos; double c[200001]; int used[200001]; void dfs(int i) { //cout<<i<<" "<<c[i]<<endl; used[i]=1; curr.push_back(i); sum+=c[i]; for(int j=0; j<v[i].size(); j++) { pair<int,int> nb=v[i][j]; int x=nb.first; int y=nb.second; if(used[x]&&c[x]+c[i]!=y)pos=0; else if(!used[x]) { c[x]=y-c[i]; dfs(x); } } } double f[100001]; void try_(int i,double val) { //cout<<endl; pos=1; sum=0; c[i]=val; dfs(i); ans=min(ans,sum); for(int j=0; j<curr.size(); j++) { if(ans==sum&&pos)f[curr[j]]=c[curr[j]]; used[curr[j]]=0; } curr.clear(); } void solve() { ans=1e9; for(int i=1; i<=n; i++) { if(!used[i]) { ans=1e9; try_(i,2); try_(i,1.5); try_(i,1); try_(i,0.5); try_(i,0); try_(i,-0.5); try_(i,-1); try_(i,-1.5); if(ans==1e9) { cout<<"NO"<<endl; exit(0); } } } cout<<"YES"<<endl; for(int i=1; i<=n; i++) cout<<f[i]<<" "; cout<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); solve(); return 0; }

Compilation message (stderr)

Graph.cpp: In function 'void dfs(int)':
Graph.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
Graph.cpp: In function 'void try_(int, double)':
Graph.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int j=0; j<curr.size(); j++)
      |                  ~^~~~~~~~~~~~
#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...