Submission #932293

# Submission time Handle Problem Language Result Execution time Memory
932293 2024-02-23T07:06:02 Z UmairAhmadMirza Graph (BOI20_graph) C++17
17 / 100
700 ms 6760 KB
#include <bits/stdc++.h>
using namespace std;
int const N=1005;
double const inf=1e9+5;
vector<pair<int,int>> adj[N];
double edge[N][N];
vector<int> com[N];
int cc=0;
int rep[N];
double X[N];
double ct[N];
double val[N];
int n,m;
void cc_find(int node,int xx,int c){
  ct[node]=c;
  X[node]=xx;
  rep[node]=cc;
  com[cc].push_back(node);
  for(auto i:adj[node])
    if(rep[i.first]==0)
      cc_find(i.first,-xx,i.second-c);
}
double answer(int c,double x){
  double v=0.0;
  for(int i:com[c])
    for(int j:com[c])
      if(edge[i][j]>0){
        v=(X[i]+X[j])*x;
        v+=ct[i]+ct[j];
        if(v!=edge[i][j])
          return inf;
      }
  double sm=0.0;
  for(auto i:com[c])
    sm+=abs((X[i]*x)+ct[i]);
  return sm;
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int u,v,w;
    cin>>u>>v>>w;
    adj[u].push_back({v,w});
    adj[v].push_back({u,w});
    if(edge[u][v]>0 && edge[u][v]!=w){
      cout<<"NO"<<endl;
      return 0;
    }
    edge[v][u]=w;
    edge[u][v]=w;
  }
  for(int i=1;i<=n;i++){
    if(rep[i]==0){
      cc++;
      cc_find(i,1.0,0.0);
    }
  }
  double ans=0.0;
  for(int c=1;c<=cc;c++){
    double sm=inf;
    double xx=-3;
    for(double t=0;t<=1000;t++){
      double x=-100.0+((0.5)*t);
      // cout<<x<<endl;
      if(answer(c,x)<sm){
        sm=answer(c,x);
        xx=x;
      }
    }
    if(sm==inf){
      cout<<"NO"<<endl;
      return 0;
    }
    for(auto i:com[c])
      val[i]=(X[i]*xx)+ct[i];
  }
  cout<<fixed;
  cout<<"YES"<<endl;
  for(int i=1;i<=n;i++)
    cout<<setprecision(10)<<val[i]<<' ';
  cout<<endl;
  // cout<<ans<<endl;
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:58:10: warning: unused variable 'ans' [-Wunused-variable]
   58 |   double ans=0.0;
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 600 KB answer = NO
5 Correct 1 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 1 ms 348 KB answer = NO
10 Correct 1 ms 500 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 344 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 344 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 1 ms 348 KB answer = YES
19 Correct 1 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 1 ms 348 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 600 KB answer = NO
5 Correct 1 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 1 ms 348 KB answer = NO
10 Correct 1 ms 500 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 344 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 344 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 1 ms 348 KB answer = YES
19 Correct 1 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 1 ms 348 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Correct 11 ms 2392 KB answer = YES
25 Correct 4 ms 604 KB answer = YES
26 Correct 9 ms 2640 KB answer = YES
27 Correct 1 ms 2396 KB answer = YES
28 Correct 2 ms 860 KB answer = YES
29 Correct 11 ms 860 KB answer = YES
30 Correct 2 ms 860 KB answer = NO
31 Correct 2 ms 604 KB answer = YES
32 Correct 1 ms 600 KB answer = YES
33 Correct 1 ms 604 KB answer = YES
34 Correct 2 ms 860 KB answer = YES
35 Correct 1 ms 604 KB answer = YES
36 Correct 1 ms 604 KB answer = YES
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 600 KB answer = NO
5 Correct 1 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 1 ms 348 KB answer = NO
10 Correct 1 ms 500 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 344 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 344 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 1 ms 348 KB answer = YES
19 Correct 1 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 1 ms 348 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Correct 11 ms 2392 KB answer = YES
25 Correct 4 ms 604 KB answer = YES
26 Correct 9 ms 2640 KB answer = YES
27 Correct 1 ms 2396 KB answer = YES
28 Correct 2 ms 860 KB answer = YES
29 Correct 11 ms 860 KB answer = YES
30 Correct 2 ms 860 KB answer = NO
31 Correct 2 ms 604 KB answer = YES
32 Correct 1 ms 600 KB answer = YES
33 Correct 1 ms 604 KB answer = YES
34 Correct 2 ms 860 KB answer = YES
35 Correct 1 ms 604 KB answer = YES
36 Correct 1 ms 604 KB answer = YES
37 Correct 42 ms 1448 KB answer = YES
38 Correct 2 ms 1372 KB answer = YES
39 Correct 279 ms 6760 KB answer = YES
40 Correct 82 ms 6604 KB answer = YES
41 Correct 76 ms 6492 KB answer = NO
42 Execution timed out 727 ms 6600 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 600 KB answer = NO
5 Correct 1 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 1 ms 348 KB answer = NO
10 Correct 1 ms 500 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 344 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 344 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 1 ms 348 KB answer = YES
19 Correct 1 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 1 ms 348 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Correct 11 ms 2392 KB answer = YES
25 Correct 4 ms 604 KB answer = YES
26 Correct 9 ms 2640 KB answer = YES
27 Correct 1 ms 2396 KB answer = YES
28 Correct 2 ms 860 KB answer = YES
29 Correct 11 ms 860 KB answer = YES
30 Correct 2 ms 860 KB answer = NO
31 Correct 2 ms 604 KB answer = YES
32 Correct 1 ms 600 KB answer = YES
33 Correct 1 ms 604 KB answer = YES
34 Correct 2 ms 860 KB answer = YES
35 Correct 1 ms 604 KB answer = YES
36 Correct 1 ms 604 KB answer = YES
37 Correct 42 ms 1448 KB answer = YES
38 Correct 2 ms 1372 KB answer = YES
39 Correct 279 ms 6760 KB answer = YES
40 Correct 82 ms 6604 KB answer = YES
41 Correct 76 ms 6492 KB answer = NO
42 Execution timed out 727 ms 6600 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 600 KB answer = NO
5 Correct 1 ms 348 KB answer = YES
6 Correct 0 ms 348 KB answer = YES
7 Correct 0 ms 348 KB answer = YES
8 Correct 0 ms 348 KB answer = YES
9 Correct 1 ms 348 KB answer = NO
10 Correct 1 ms 500 KB answer = YES
11 Correct 0 ms 348 KB answer = YES
12 Correct 0 ms 348 KB answer = NO
13 Correct 0 ms 344 KB answer = YES
14 Correct 0 ms 348 KB answer = YES
15 Correct 0 ms 348 KB answer = YES
16 Correct 0 ms 344 KB answer = YES
17 Correct 0 ms 348 KB answer = YES
18 Correct 1 ms 348 KB answer = YES
19 Correct 1 ms 348 KB answer = YES
20 Correct 0 ms 348 KB answer = YES
21 Correct 0 ms 348 KB answer = YES
22 Correct 1 ms 348 KB answer = NO
23 Correct 1 ms 348 KB answer = NO
24 Correct 11 ms 2392 KB answer = YES
25 Correct 4 ms 604 KB answer = YES
26 Correct 9 ms 2640 KB answer = YES
27 Correct 1 ms 2396 KB answer = YES
28 Correct 2 ms 860 KB answer = YES
29 Correct 11 ms 860 KB answer = YES
30 Correct 2 ms 860 KB answer = NO
31 Correct 2 ms 604 KB answer = YES
32 Correct 1 ms 600 KB answer = YES
33 Correct 1 ms 604 KB answer = YES
34 Correct 2 ms 860 KB answer = YES
35 Correct 1 ms 604 KB answer = YES
36 Correct 1 ms 604 KB answer = YES
37 Correct 42 ms 1448 KB answer = YES
38 Correct 2 ms 1372 KB answer = YES
39 Correct 279 ms 6760 KB answer = YES
40 Correct 82 ms 6604 KB answer = YES
41 Correct 76 ms 6492 KB answer = NO
42 Execution timed out 727 ms 6600 KB Time limit exceeded
43 Halted 0 ms 0 KB -