# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
558363 | hibiki | Graph (BOI20_graph) | C++11 | 147 ms | 22476 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |