제출 #558363

#제출 시각아이디문제언어결과실행 시간메모리
558363hibikiGraph (BOI20_graph)C++11
100 / 100
147 ms22476 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define F first #define S second int n,m; int na[100005],nb[100005]; double x,ans[100005]; bool done[100005],found; vector<int> has; vector<pair<int,int> > v[100005]; void dfs(int nw, int fa) { has.pb(nw); for(pair<int,int> go: v[nw]) { if(go.F == fa) continue; int ga = na[nw] * -1, gb = go.S - nb[nw]; if(!done[go.F]) { done[go.F] = true; na[go.F] = ga; nb[go.F] = gb; dfs(go.F,nw); } else if(na[go.F] != ga) { double temp = (double)(nb[go.F] - gb) / (double)(ga - na[go.F]); if(found && temp != x) { printf("NO\n"); exit(0); } x = temp; found = true; } else if(nb[go.F] != gb) { printf("NO\n"); exit(0); } } } int main() { scanf("%d %d",&n,&m); for(int i = 0; i < m; i++) { int a,b,c; scanf("%d %d %d",&a,&b,&c); v[a].pb({b,c}); v[b].pb({a,c}); } for(int i = 1; i <= n; i++) { if(done[i]) continue; has.clear(); found = false; done[i] = true; na[i] = 1; nb[i] = 0; dfs(i,-1); if(!found) { vector<int> ss; for(int po: has) ss.pb(-na[po] * nb[po]); sort(ss.begin(),ss.end()); x = (double)ss[ss.size() / 2]; } for(int po: has) ans[po] = na[po] * x + nb[po]; } printf("YES\n"); for(int i = 1; i <= n; i++) printf("%lf ",ans[i]); printf("\n"); return 0; }

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

Graph.cpp: In function 'int main()':
Graph.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         scanf("%d %d %d",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...