제출 #84247

#제출 시각아이디문제언어결과실행 시간메모리
84247IOrtroiiiPipes (BOI13_pipes)C++14
74.07 / 100
91 ms9380 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m; int deg[N]; bool ok[N]; long long a[N], ans[N]; vector<pair<int,int>> g[N]; void dfs(int u,int p) { } int main() { scanf("%d %d", &n, &m); if (n < m) return printf("0\n"),0; for (int i = 1; i <= n; ++i) scanf("%lld", a + i); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d %d", &u, &v); ++deg[u], ++deg[v]; g[u].push_back({v, i}), g[v].push_back({u, i}); } queue<int> q; for (int u = 1; u <= n; ++u) if (deg[u] == 1) { q.push(u); } while (!q.empty()) { int u = q.front(); q.pop(); for (auto e : g[u]) { int v = e.first; int id = e.second; if (ok[v] == false) { ans[id] = a[u]; a[u] -= ans[id]; a[v] -= ans[id]; ok[u] = true; if (--deg[v] == 1) { q.push(v); } } } } for (int i = 1; i <= n; ++i) if (a[i]) return printf("0\n"),0; for (int i = 1; i <= m; ++i) if (ans[i] > (long long) 5e8 || ans[i] < (long long) -5e8) { return printf("0\n"),0; } for (int i = 1; i <= m; ++i) printf("%lld\n", 2 * ans[i]); }

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

pipes.cpp: In function 'int main()':
pipes.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:19:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
                               ~~~~~^~~~~~~~~~~~~~~
pipes.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u, v; scanf("%d %d", &u, &v);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...