# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
558353 |
2022-05-07T07:12:18 Z |
hibiki |
Graph (BOI20_graph) |
C++11 |
|
3 ms |
2644 KB |
#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];
map<pair<int,int>,int> mp;
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)
{
x = (double)(nb[go.F] - gb) / (double)(ga - na[go.F]);
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);
if(!mp[{a,b}])
{
mp[{a,b}] = mp[{b,a}] = c;
v[a].pb({b,c});
v[b].pb({a,c});
}
else if(mp[{a,b}] != c)
{
printf("NO\n");
return 0;
}
}
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,i);
if(!found)
{
vector<int> ss;
for(int po: has)
ss.pb(-na[po] * nb[po]);
sort(ss.begin(),ss.end());
int mid = ss.size() >> 2;
x = ss[mid];
}
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;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
Graph.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d %d %d",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
3 ms |
2644 KB |
answer = YES |
6 |
Incorrect |
2 ms |
2644 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
3 ms |
2644 KB |
answer = YES |
6 |
Incorrect |
2 ms |
2644 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
3 ms |
2644 KB |
answer = YES |
6 |
Incorrect |
2 ms |
2644 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
3 ms |
2644 KB |
answer = YES |
6 |
Incorrect |
2 ms |
2644 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
3 ms |
2644 KB |
answer = YES |
6 |
Incorrect |
2 ms |
2644 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |