# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1107965 |
2024-11-02T13:08:39 Z |
simona1230 |
Graph (BOI20_graph) |
C++17 |
|
414 ms |
3836 KB |
#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];
const double minn=0.0000001;
void dfs(int i)
{
//cout<<i<<" "<<c[i]<<endl;
used[i]=1;
curr.push_back(i);
sum+=abs(c[i]);
for(int j=0; j<v[i].size(); j++)
{
pair<int,int> nb=v[i][j];
int x=nb.first;
double y=nb.second;
double diff=c[x]+c[i]-y;
if(used[x]&&(diff>=minn||diff<=-minn))
{
//cout<<i<<" x "<<x<<" "<<c[x]+c[i]<<" "<<y<<endl;
pos=0;
}
else if(!used[x])
{
if(y==c[i])c[x]=0;
else
{
if(y-c[i]<minn&&y-c[i]>-minn)c[x]=0;
else c[x]=y-c[i];
}
dfs(x);
}
}
}
double f[100001];
void try_(int i,double val)
{
//cout<<endl;
for(int j=0; j<curr.size(); j++)
{
used[curr[j]]=0;
}
curr.clear();
//cout<<val<<endl;
pos=1;
sum=0;
c[i]=val;
dfs(i);
if(pos&&sum<ans)ans=sum;
//cout<<sum<<" "<<ans<<" "<<pos<<endl;
for(int j=0; j<curr.size(); j++)
{
double diff=ans-sum;
if(diff>-minn&&diff<minn&&pos)f[curr[j]]=c[curr[j]];
}
}
void solve()
{
for(int i=1; i<=n; i++)
{
if(!used[i])
{
ans=100000;
double x=0.00001;
for(double val=-2;val<0;val=val+x)
{
try_(i,val);
}
try_(i,0);
for(double val=0.00001;val<=2;val=val+x)
{
try_(i,val);
}
if(ans==100000)
{
cout<<"NO"<<endl;
exit(0);
}
}
}
//cout<<ans<<endl;
cout<<"YES"<<endl;
for(int i=1; i<=n; i++)
cout<<fixed<<setprecision(7)<<f[i]<<" ";
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
read();
solve();
return 0;
}
Compilation message
Graph.cpp: In function 'void dfs(int)':
Graph.cpp:33: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]
33 | for(int j=0; j<v[i].size(); j++)
| ~^~~~~~~~~~~~
Graph.cpp: In function 'void try_(int, double)':
Graph.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int j=0; j<curr.size(); j++)
| ~^~~~~~~~~~~~
Graph.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int j=0; j<curr.size(); j++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3724 KB |
answer = YES |
2 |
Correct |
11 ms |
3720 KB |
answer = YES |
3 |
Correct |
14 ms |
3664 KB |
answer = YES |
4 |
Correct |
14 ms |
3664 KB |
answer = NO |
5 |
Correct |
27 ms |
3664 KB |
answer = YES |
6 |
Correct |
14 ms |
3664 KB |
answer = YES |
7 |
Correct |
15 ms |
3664 KB |
answer = YES |
8 |
Correct |
20 ms |
3664 KB |
answer = YES |
9 |
Correct |
19 ms |
3716 KB |
answer = NO |
10 |
Correct |
22 ms |
3664 KB |
answer = YES |
11 |
Correct |
21 ms |
3664 KB |
answer = YES |
12 |
Correct |
25 ms |
3664 KB |
answer = NO |
13 |
Correct |
41 ms |
3664 KB |
answer = YES |
14 |
Correct |
23 ms |
3716 KB |
answer = YES |
15 |
Correct |
22 ms |
3664 KB |
answer = YES |
16 |
Correct |
23 ms |
3664 KB |
answer = YES |
17 |
Correct |
6 ms |
3664 KB |
answer = YES |
18 |
Correct |
7 ms |
3664 KB |
answer = YES |
19 |
Correct |
36 ms |
3664 KB |
answer = YES |
20 |
Correct |
17 ms |
3664 KB |
answer = YES |
21 |
Correct |
11 ms |
3664 KB |
answer = YES |
22 |
Correct |
10 ms |
3664 KB |
answer = NO |
23 |
Correct |
36 ms |
3664 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3724 KB |
answer = YES |
2 |
Correct |
11 ms |
3720 KB |
answer = YES |
3 |
Correct |
14 ms |
3664 KB |
answer = YES |
4 |
Correct |
14 ms |
3664 KB |
answer = NO |
5 |
Correct |
27 ms |
3664 KB |
answer = YES |
6 |
Correct |
14 ms |
3664 KB |
answer = YES |
7 |
Correct |
15 ms |
3664 KB |
answer = YES |
8 |
Correct |
20 ms |
3664 KB |
answer = YES |
9 |
Correct |
19 ms |
3716 KB |
answer = NO |
10 |
Correct |
22 ms |
3664 KB |
answer = YES |
11 |
Correct |
21 ms |
3664 KB |
answer = YES |
12 |
Correct |
25 ms |
3664 KB |
answer = NO |
13 |
Correct |
41 ms |
3664 KB |
answer = YES |
14 |
Correct |
23 ms |
3716 KB |
answer = YES |
15 |
Correct |
22 ms |
3664 KB |
answer = YES |
16 |
Correct |
23 ms |
3664 KB |
answer = YES |
17 |
Correct |
6 ms |
3664 KB |
answer = YES |
18 |
Correct |
7 ms |
3664 KB |
answer = YES |
19 |
Correct |
36 ms |
3664 KB |
answer = YES |
20 |
Correct |
17 ms |
3664 KB |
answer = YES |
21 |
Correct |
11 ms |
3664 KB |
answer = YES |
22 |
Correct |
10 ms |
3664 KB |
answer = NO |
23 |
Correct |
36 ms |
3664 KB |
answer = NO |
24 |
Correct |
414 ms |
3836 KB |
answer = YES |
25 |
Incorrect |
219 ms |
3664 KB |
participant answer is larger than the answer of jury |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3724 KB |
answer = YES |
2 |
Correct |
11 ms |
3720 KB |
answer = YES |
3 |
Correct |
14 ms |
3664 KB |
answer = YES |
4 |
Correct |
14 ms |
3664 KB |
answer = NO |
5 |
Correct |
27 ms |
3664 KB |
answer = YES |
6 |
Correct |
14 ms |
3664 KB |
answer = YES |
7 |
Correct |
15 ms |
3664 KB |
answer = YES |
8 |
Correct |
20 ms |
3664 KB |
answer = YES |
9 |
Correct |
19 ms |
3716 KB |
answer = NO |
10 |
Correct |
22 ms |
3664 KB |
answer = YES |
11 |
Correct |
21 ms |
3664 KB |
answer = YES |
12 |
Correct |
25 ms |
3664 KB |
answer = NO |
13 |
Correct |
41 ms |
3664 KB |
answer = YES |
14 |
Correct |
23 ms |
3716 KB |
answer = YES |
15 |
Correct |
22 ms |
3664 KB |
answer = YES |
16 |
Correct |
23 ms |
3664 KB |
answer = YES |
17 |
Correct |
6 ms |
3664 KB |
answer = YES |
18 |
Correct |
7 ms |
3664 KB |
answer = YES |
19 |
Correct |
36 ms |
3664 KB |
answer = YES |
20 |
Correct |
17 ms |
3664 KB |
answer = YES |
21 |
Correct |
11 ms |
3664 KB |
answer = YES |
22 |
Correct |
10 ms |
3664 KB |
answer = NO |
23 |
Correct |
36 ms |
3664 KB |
answer = NO |
24 |
Correct |
414 ms |
3836 KB |
answer = YES |
25 |
Incorrect |
219 ms |
3664 KB |
participant answer is larger than the answer of jury |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3724 KB |
answer = YES |
2 |
Correct |
11 ms |
3720 KB |
answer = YES |
3 |
Correct |
14 ms |
3664 KB |
answer = YES |
4 |
Correct |
14 ms |
3664 KB |
answer = NO |
5 |
Correct |
27 ms |
3664 KB |
answer = YES |
6 |
Correct |
14 ms |
3664 KB |
answer = YES |
7 |
Correct |
15 ms |
3664 KB |
answer = YES |
8 |
Correct |
20 ms |
3664 KB |
answer = YES |
9 |
Correct |
19 ms |
3716 KB |
answer = NO |
10 |
Correct |
22 ms |
3664 KB |
answer = YES |
11 |
Correct |
21 ms |
3664 KB |
answer = YES |
12 |
Correct |
25 ms |
3664 KB |
answer = NO |
13 |
Correct |
41 ms |
3664 KB |
answer = YES |
14 |
Correct |
23 ms |
3716 KB |
answer = YES |
15 |
Correct |
22 ms |
3664 KB |
answer = YES |
16 |
Correct |
23 ms |
3664 KB |
answer = YES |
17 |
Correct |
6 ms |
3664 KB |
answer = YES |
18 |
Correct |
7 ms |
3664 KB |
answer = YES |
19 |
Correct |
36 ms |
3664 KB |
answer = YES |
20 |
Correct |
17 ms |
3664 KB |
answer = YES |
21 |
Correct |
11 ms |
3664 KB |
answer = YES |
22 |
Correct |
10 ms |
3664 KB |
answer = NO |
23 |
Correct |
36 ms |
3664 KB |
answer = NO |
24 |
Correct |
414 ms |
3836 KB |
answer = YES |
25 |
Incorrect |
219 ms |
3664 KB |
participant answer is larger than the answer of jury |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3724 KB |
answer = YES |
2 |
Correct |
11 ms |
3720 KB |
answer = YES |
3 |
Correct |
14 ms |
3664 KB |
answer = YES |
4 |
Correct |
14 ms |
3664 KB |
answer = NO |
5 |
Correct |
27 ms |
3664 KB |
answer = YES |
6 |
Correct |
14 ms |
3664 KB |
answer = YES |
7 |
Correct |
15 ms |
3664 KB |
answer = YES |
8 |
Correct |
20 ms |
3664 KB |
answer = YES |
9 |
Correct |
19 ms |
3716 KB |
answer = NO |
10 |
Correct |
22 ms |
3664 KB |
answer = YES |
11 |
Correct |
21 ms |
3664 KB |
answer = YES |
12 |
Correct |
25 ms |
3664 KB |
answer = NO |
13 |
Correct |
41 ms |
3664 KB |
answer = YES |
14 |
Correct |
23 ms |
3716 KB |
answer = YES |
15 |
Correct |
22 ms |
3664 KB |
answer = YES |
16 |
Correct |
23 ms |
3664 KB |
answer = YES |
17 |
Correct |
6 ms |
3664 KB |
answer = YES |
18 |
Correct |
7 ms |
3664 KB |
answer = YES |
19 |
Correct |
36 ms |
3664 KB |
answer = YES |
20 |
Correct |
17 ms |
3664 KB |
answer = YES |
21 |
Correct |
11 ms |
3664 KB |
answer = YES |
22 |
Correct |
10 ms |
3664 KB |
answer = NO |
23 |
Correct |
36 ms |
3664 KB |
answer = NO |
24 |
Correct |
414 ms |
3836 KB |
answer = YES |
25 |
Incorrect |
219 ms |
3664 KB |
participant answer is larger than the answer of jury |
26 |
Halted |
0 ms |
0 KB |
- |