제출 #855001

#제출 시각아이디문제언어결과실행 시간메모리
855001hariaakas646Pipes (BOI13_pipes)C++17
44.07 / 100
70 ms16984 KiB
#include <bits/stdc++.h> using namespace std; #define scd(t) scanf("%d", &t) #define sclld(t) scanf("%lld", &t) #define forr(i, j, k) for (int i = j; i < k; i++) #define frange(i, j) forr(i, 0, j) #define all(cont) cont.begin(), cont.end() #define mp make_pair #define pb push_back #define f first #define s second typedef long long int lli; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<lli> vll; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef long double ld; void usaco() { freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin); // freopen("problem.out", "w", stdout); } int main() { // usaco(); int n, m; scd(n); scd(m); vll vec(n+1); forr(i, 1, n+1) sclld(vec[i]); if(m > n) { printf("0"); return 0; } vector<set<pii>> graph(n+1); vi deg(n+1); frange(i, m) { int a, b; scd(a); scd(b); graph[a].insert(mp(b, i)); graph[b].insert(mp(a, i)); deg[a]++; deg[b]++; } vll out(m); queue<int> q; forr(i, 1, n+1) { if(deg[i] == 1) q.push(i); } vb cyc(n+1, true); vb vis(n+1); while(q.size()) { auto x = q.front(); q.pop(); cyc[x] = false; vis[x] = true; for(auto p : graph[x]) { graph[p.f].erase(mp(x, p.s)); deg[p.f]--; out[p.s] = 2*vec[x]; vec[p.f] -= vec[x]; if(deg[p.f] == 1) q.push(p.f); } } int c = 0; forr(i, 1, n+1) { if(cyc[i]) c++; } if(c % 2==0) { printf("0"); return 0; } forr(i, 1, n+1) { if(cyc[i]) { pii p = (*graph[i].begin()); int x = p.f; int ed = p.s; lli k = 0; while(x != i) { k = vec[x] - k; x = (*graph[x].begin()).f; } lli v = (vec[i] - k)/2; out[ed] = 2 * v; x = (*graph[i].begin()).f; while(x != i) { v = vec[x] - v; pii p = *graph[x].begin(); out[p.s] = 2*v; x = p.f; } break; } } frange(i, m) printf("%lld\n", out[i]); }

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

pipes.cpp: In function 'void usaco()':
pipes.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(n);
      |     ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:38:5: note: in expansion of macro 'scd'
   38 |     scd(m);
      |     ^~~
pipes.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
pipes.cpp:41:21: note: in expansion of macro 'sclld'
   41 |     forr(i, 1, n+1) sclld(vec[i]);
      |                     ^~~~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:50:9: note: in expansion of macro 'scd'
   50 |         scd(a);
      |         ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:51:9: note: in expansion of macro 'scd'
   51 |         scd(b);
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...