# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90618 | 2018-12-22T23:59:19 Z | psmao | Pipes (BOI13_pipes) | C++14 | 224 ms | 53372 KB |
#include <bits/stdc++.h> using namespace std; #define fo(i,s,t) for(int i = s; i <= t; ++ i) #define fd(i,s,t) for(int i = s; i >= t; -- i) #define bf(i,s) for(int i = head[s]; i; i = e[i].next) #define mp make_pair #define fi first #define se second #define pii pair<int,int> #define pb push_back #define VI vector<int> #define sf scanf #define pf printf #define fp freopen #define SZ(x) ((int)(x).size()) #ifdef MPS #define D(x...) printf(x) #else #define D(x...) #endif typedef long long ll; typedef double db; typedef unsigned long long ull; const int inf = 1<<30; const ll INF = 1ll<<60; const db Inf = 1e20; const db eps = 1e-9; void gmax(int &a,int b){a = (a > b ? a : b);} void gmin(int &a,int b){a = (a < b ? a : b);} const int maxn = 100050; int n, m, deg[maxn], s[maxn]; ll v[maxn]; vector<pii> adj[maxn]; queue<int> Q; VI pathx, nodex; bool vis[maxn]; int main() { #ifdef MPS fp("1.in","r",stdin); fp("1.out","w",stdout); #endif sf("%d%d",&n,&m); if(m != n-1 && m != n) return 0 * pf("0\n"); fo(i,1,n) sf("%d",&s[i]); fo(i,1,m) { int u, v; sf("%d%d",&u,&v); adj[u].pb(mp(v,i)); adj[v].pb(mp(u,i)); deg[u] ++; deg[v] ++; } fo(i,1,n) if(deg[i] == 1) Q.push(i); while(!Q.empty()) { int h = Q.front(); Q.pop(); vis[h] = true; for(auto p : adj[h]) if(!vis[p.fi]) { v[p.se] = s[h]; s[p.fi] -= s[h]; if((--deg[p.fi]) == 1) Q.push(p.fi); } } fo(i,1,n) if(deg[i] == 2) { int x = i; ll cur = 0ll; while(1) { bool contin = false; deg[x] --; cur = s[x] - cur; nodex.pb(x); for(auto p : adj[x]) if(deg[p.fi] == 2) {x = p.fi; pathx.pb(p.se); contin = true; break;} if(!contin) // we have iterated the cycle already { for(auto p : adj[x]) if(p.fi == i) {pathx.pb(p.se); break;} if(cur&1) return 0 * pf("0\n"); cur >>= 1; v[pathx.back()] = cur; for(int p = 0; p < SZ(pathx)-1; ++ p) {cur = s[nodex[p]] - cur; v[pathx[p]] = cur;} break; } } break; } fo(i,1,m) cout << v[i]*2 << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 2808 KB | Output is correct |
2 | Correct | 4 ms | 2912 KB | Output is correct |
3 | Correct | 5 ms | 3152 KB | Output is correct |
4 | Correct | 192 ms | 10696 KB | Output is correct |
5 | Correct | 3 ms | 10696 KB | Output is correct |
6 | Correct | 3 ms | 10696 KB | Output is correct |
7 | Correct | 3 ms | 10696 KB | Output is correct |
8 | Correct | 3 ms | 10696 KB | Output is correct |
9 | Correct | 5 ms | 10696 KB | Output is correct |
10 | Correct | 5 ms | 10696 KB | Output is correct |
11 | Correct | 5 ms | 10696 KB | Output is correct |
12 | Correct | 5 ms | 10696 KB | Output is correct |
13 | Correct | 154 ms | 10740 KB | Output is correct |
14 | Correct | 185 ms | 13260 KB | Output is correct |
15 | Correct | 200 ms | 15096 KB | Output is correct |
16 | Correct | 168 ms | 15536 KB | Output is correct |
17 | Correct | 195 ms | 17920 KB | Output is correct |
18 | Correct | 199 ms | 19620 KB | Output is correct |
19 | Correct | 197 ms | 20528 KB | Output is correct |
20 | Correct | 4 ms | 20528 KB | Output is correct |
21 | Correct | 5 ms | 20528 KB | Output is correct |
22 | Correct | 197 ms | 22748 KB | Output is correct |
23 | Correct | 161 ms | 22812 KB | Output is correct |
24 | Correct | 196 ms | 25556 KB | Output is correct |
25 | Correct | 158 ms | 25892 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 25892 KB | Output is correct |
2 | Correct | 5 ms | 25892 KB | Output is correct |
3 | Incorrect | 182 ms | 28296 KB | Output isn't correct |
4 | Correct | 4 ms | 28296 KB | Output is correct |
5 | Correct | 4 ms | 28296 KB | Output is correct |
6 | Correct | 3 ms | 28296 KB | Output is correct |
7 | Correct | 4 ms | 28296 KB | Output is correct |
8 | Correct | 3 ms | 28296 KB | Output is correct |
9 | Incorrect | 4 ms | 28296 KB | Output isn't correct |
10 | Correct | 3 ms | 28296 KB | Output is correct |
11 | Correct | 3 ms | 28296 KB | Output is correct |
12 | Correct | 3 ms | 28296 KB | Output is correct |
13 | Correct | 3 ms | 28296 KB | Output is correct |
14 | Correct | 3 ms | 28296 KB | Output is correct |
15 | Correct | 5 ms | 28296 KB | Output is correct |
16 | Correct | 5 ms | 28296 KB | Output is correct |
17 | Incorrect | 5 ms | 28296 KB | Output isn't correct |
18 | Correct | 4 ms | 28296 KB | Output is correct |
19 | Correct | 4 ms | 28296 KB | Output is correct |
20 | Correct | 3 ms | 28296 KB | Output is correct |
21 | Correct | 3 ms | 28296 KB | Output is correct |
22 | Correct | 5 ms | 28296 KB | Output is correct |
23 | Correct | 157 ms | 29092 KB | Output is correct |
24 | Correct | 217 ms | 31668 KB | Output is correct |
25 | Incorrect | 184 ms | 32844 KB | Output isn't correct |
26 | Correct | 3 ms | 32844 KB | Output is correct |
27 | Correct | 4 ms | 32844 KB | Output is correct |
28 | Correct | 4 ms | 32844 KB | Output is correct |
29 | Correct | 4 ms | 32844 KB | Output is correct |
30 | Correct | 196 ms | 34372 KB | Output is correct |
31 | Correct | 224 ms | 36452 KB | Output is correct |
32 | Correct | 206 ms | 37856 KB | Output is correct |
33 | Incorrect | 201 ms | 39432 KB | Output isn't correct |
34 | Correct | 4 ms | 39432 KB | Output is correct |
35 | Correct | 3 ms | 39432 KB | Output is correct |
36 | Correct | 3 ms | 39432 KB | Output is correct |
37 | Correct | 3 ms | 39432 KB | Output is correct |
38 | Correct | 216 ms | 40964 KB | Output is correct |
39 | Correct | 210 ms | 42564 KB | Output is correct |
40 | Correct | 215 ms | 44236 KB | Output is correct |
41 | Incorrect | 212 ms | 45936 KB | Output isn't correct |
42 | Correct | 4 ms | 45936 KB | Output is correct |
43 | Correct | 4 ms | 45936 KB | Output is correct |
44 | Correct | 4 ms | 45936 KB | Output is correct |
45 | Correct | 4 ms | 45936 KB | Output is correct |
46 | Correct | 220 ms | 47208 KB | Output is correct |
47 | Correct | 217 ms | 48984 KB | Output is correct |
48 | Correct | 212 ms | 50712 KB | Output is correct |
49 | Incorrect | 191 ms | 51660 KB | Output isn't correct |
50 | Correct | 4 ms | 51660 KB | Output is correct |
51 | Correct | 4 ms | 51660 KB | Output is correct |
52 | Correct | 3 ms | 51660 KB | Output is correct |
53 | Correct | 4 ms | 51660 KB | Output is correct |
54 | Correct | 213 ms | 53372 KB | Output is correct |