# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
670446 | 2022-12-09T06:30:24 Z | jamezzz | Graph (BOI20_graph) | C++17 | 2 ms | 2664 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define sf scanf #define pf printf #define pb push_back typedef pair<int,int> ii; typedef tuple<int,int,int> iii; #define maxn 100005 int n,m; double ans[maxn]; ii val[maxn]; vector<int> sub; vector<ii> AL[maxn]; vector<iii> back; void dfs(int u,int p){ sub.pb(u); for(auto[v,w]:AL[u]){ if(v==p)continue; if(val[v].fi!=0)back.pb({u,v,w}); else{ val[v].fi=-val[u].fi; val[v].se=w-val[u].se; dfs(v,u); } } } int main(){ sf("%d%d",&n,&m); for(int i=0;i<m;++i){ int a,b,c;sf("%d%d%d",&a,&b,&c); AL[a].pb({b,c}); AL[b].pb({a,c}); } for(int i=1;i<=n;++i){ if(val[i].fi!=0)continue; back.clear(); sub.clear(); val[i]={1,0}; dfs(i,-1); if(back.size()==0){ for(int i:sub){ ans[i]=val[i].se; } } else{ double x=0; bool done=false,pos=true; for(auto[a,b,c]:back){ auto[a1,a2]=val[a]; auto[b1,b2]=val[b]; if(done){ if(a1*x+a2+b1*x+b2!=c){ pos=false; break; } } else{ if(a1+b1==0){ if(a2+b2!=c){ pos=false; break; } } else{ x=(double)(c-a2-b2)/(a1+b1); done=true; } } } if(!pos){ pf("NO\n"); exit(0); } for(int i:sub){ ans[i]=val[i].fi*x+val[i].se; } } } pf("YES\n"); for(int i=1;i<=n;++i){ pf("%f ",ans[i]); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | answer = YES |
2 | Correct | 2 ms | 2644 KB | answer = YES |
3 | Correct | 2 ms | 2644 KB | answer = YES |
4 | Correct | 1 ms | 2644 KB | answer = NO |
5 | Correct | 2 ms | 2664 KB | answer = YES |
6 | Incorrect | 2 ms | 2644 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | answer = YES |
2 | Correct | 2 ms | 2644 KB | answer = YES |
3 | Correct | 2 ms | 2644 KB | answer = YES |
4 | Correct | 1 ms | 2644 KB | answer = NO |
5 | Correct | 2 ms | 2664 KB | answer = YES |
6 | Incorrect | 2 ms | 2644 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | answer = YES |
2 | Correct | 2 ms | 2644 KB | answer = YES |
3 | Correct | 2 ms | 2644 KB | answer = YES |
4 | Correct | 1 ms | 2644 KB | answer = NO |
5 | Correct | 2 ms | 2664 KB | answer = YES |
6 | Incorrect | 2 ms | 2644 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | answer = YES |
2 | Correct | 2 ms | 2644 KB | answer = YES |
3 | Correct | 2 ms | 2644 KB | answer = YES |
4 | Correct | 1 ms | 2644 KB | answer = NO |
5 | Correct | 2 ms | 2664 KB | answer = YES |
6 | Incorrect | 2 ms | 2644 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | answer = YES |
2 | Correct | 2 ms | 2644 KB | answer = YES |
3 | Correct | 2 ms | 2644 KB | answer = YES |
4 | Correct | 1 ms | 2644 KB | answer = NO |
5 | Correct | 2 ms | 2664 KB | answer = YES |
6 | Incorrect | 2 ms | 2644 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |