제출 #411508

#제출 시각아이디문제언어결과실행 시간메모리
411508Ruxandra985Graph (BOI20_graph)C++14
0 / 100
3 ms2636 KiB
#include <bits/stdc++.h> #define DIMN 100010 using namespace std; double sol[DIMN]; int f[DIMN] , f2[DIMN]; vector <pair <int , int> > v[DIMN]; pair <int , int> cod[DIMN]; deque <int> dq; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , m , i , a , y , z , found , nod , vecin , tip; double x; fscanf (fin,"%d%d",&n,&m); for (i = 1 ; i <= m ; i++){ fscanf (fin,"%d%d%d",&a,&y,&z); v[a].push_back(make_pair(y , z)); v[y].push_back(make_pair(a , z)); } for (int j = 1 ; j <= n ; j++){ if (f2[j]) continue; cod[j] = make_pair(0 , j); dq.push_back(j); f[j] = 1; found = 0; while (!dq.empty() && !found){ nod = dq.front(); dq.pop_front(); for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i].first; tip = v[nod][i].second; if (!f[vecin]){ dq.push_back(vecin); f[vecin] = 1; cod[vecin] = make_pair(tip - cod[nod].first , -cod[nod].second); } else { /// momentul sa vezi daca relatiile sunt echivalente, contradictorii /// sau daca sau solutia x if (cod[vecin] == make_pair(tip - cod[nod].first , -cod[nod].second)) continue; /// echivalent if (cod[vecin].second == -cod[nod].second && cod[vecin].first != tip - cod[nod].first){ fprintf (fout,"NO"); /// contradictorii return 0; } if (cod[vecin].second != -cod[nod].second){ if (cod[vecin].second == 1){ x = 1.0 * (tip - cod[nod].first - cod[vecin].first) / 2; found = 1; break; /// ai aflat x } else { x = 1.0 * (cod[vecin].first - tip + cod[nod].first) / 2; found = 1; break; } } } } } if (!found){ x = 0; found = 1; } if (found){ dq.clear(); dq.push_back(j); f2[j] = 2; sol[j] = x; while (!dq.empty()){ nod = dq.front(); dq.pop_front(); for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i].first; tip = v[nod][i].second; if (f2[vecin] != 2){ dq.push_back(vecin); f2[vecin] = 2; sol[vecin] = tip - sol[nod]; } else { if (sol[vecin] != tip - sol[nod]){ fprintf (fout,"NO"); return 0; } } } } } } cout << "YES\n"; for (i = 1 ; i <= n ; i++){ cout << sol[i] << " "; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Graph.cpp: In function 'int main()':
Graph.cpp:36:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (i = 0 ; i < v[nod].size() ; i++){
      |                          ~~^~~~~~~~~~~~~~~
Graph.cpp:106:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |                 for (i = 0 ; i < v[nod].size() ; i++){
      |                              ~~^~~~~~~~~~~~~~~
Graph.cpp:15:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     fscanf (fin,"%d%d",&n,&m);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~
Graph.cpp:17:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         fscanf (fin,"%d%d%d",&a,&y,&z);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...