# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58596 |
2018-07-18T11:17:26 Z |
Batrr |
Pipes (BOI13_pipes) |
C++14 |
|
444 ms |
51032 KB |
#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=5e5+123,inf=1e18,mod=1e9+7,N=360360,LOG=20;
vector< pair<int,int> >g[maxn],G[maxn],path;
ll n,m,cnt[maxn],ans[maxn],a[maxn],mm;
bitset<maxn>used;
void dfs(int v,int st){
used[v]=1;
for(int i=0;i<G[v].size();i++){
int to=G[v][i].f;
if(to==st)
path.pb(G[v][i]);
if(!used[to]){
path.pb(G[v][i]);
dfs(to,st);
}
}
}
int main(){
#ifdef LOCAL
freopen ("test.in", "r", stdin);
#endif
IOS
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++){
int v,u;
cin>>v>>u;
g[v].pb({u,i});
g[u].pb({v,i});
}
queue<int>q;
for(int i=1;i<=n;i++){
cnt[i]=g[i].size();
if(cnt[i]==1)
q.push(i);
}
while(!q.empty()){
int v=q.front();
q.pop();
used[v]=1;
for(auto to:g[v])
if(!used[to.f]){
cnt[to.f]--;
if(cnt[to.f]==1)
q.push(to.f);
ans[to.s]=a[v]*2;
a[to.f]-=a[v];
}
}
mm=0;
for(int v=1;v<=n;v++){
if(used[v])
continue;
for(auto to:g[v])
if(!used[to.f]){
mm++;
G[v].pb(to);
}
}
for(int i=1;i<=n;i++)
if(!used[i] && G[i].size()!=2)
m=-1;
if( n==used.count()){
for(int i=1;i<=m;i++)
cout<<ans[i]<<endl;
return 0;
}
if( (n-used.count())%2==0 || mm!=n-used.count())
cout<<0,exit(0);
for(int i=1;i<=n;i++)
if(!used[i]){
dfs(i,i);
if( (n-used.count())!=0 )
cout<<0,exit(0);
ll x=0;
for(int i=0;i<path.size();i++){
if(i%2==0)
x+=a[path[i].f];
else
x-=a[path[i].f];
}
a[path[path.size()-1].f]-=x;
a[path[0].f]-=x;
for(int i=1;i<path.size();i++){
a[path[i].f]-=a[path[i-1].f];
a[path[i-1].f]-=a[path[i-1].f];
}
for(int i=1;i<=m;i++)
cout<<ans[i]<<endl;
break;
}
}
Compilation message
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<G[v].size();i++){
~^~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:79:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if( n==used.count()){
~^~~~~~~~~~~~~~
pipes.cpp:84:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if( (n-used.count())%2==0 || mm!=n-used.count())
~~^~~~~~~~~~~~~~~~
pipes.cpp:92:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path.size();i++){
~^~~~~~~~~~~~
pipes.cpp:100:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<path.size();i++){
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Correct |
21 ms |
24040 KB |
Output is correct |
3 |
Correct |
24 ms |
24040 KB |
Output is correct |
4 |
Correct |
266 ms |
30796 KB |
Output is correct |
5 |
Correct |
25 ms |
30796 KB |
Output is correct |
6 |
Correct |
25 ms |
30796 KB |
Output is correct |
7 |
Correct |
21 ms |
30796 KB |
Output is correct |
8 |
Correct |
27 ms |
30796 KB |
Output is correct |
9 |
Correct |
28 ms |
30796 KB |
Output is correct |
10 |
Correct |
28 ms |
30796 KB |
Output is correct |
11 |
Correct |
29 ms |
30796 KB |
Output is correct |
12 |
Correct |
23 ms |
30796 KB |
Output is correct |
13 |
Correct |
213 ms |
30796 KB |
Output is correct |
14 |
Correct |
221 ms |
30796 KB |
Output is correct |
15 |
Correct |
229 ms |
30828 KB |
Output is correct |
16 |
Correct |
206 ms |
30828 KB |
Output is correct |
17 |
Correct |
314 ms |
30916 KB |
Output is correct |
18 |
Correct |
238 ms |
30916 KB |
Output is correct |
19 |
Correct |
245 ms |
30916 KB |
Output is correct |
20 |
Correct |
26 ms |
30916 KB |
Output is correct |
21 |
Correct |
22 ms |
30916 KB |
Output is correct |
22 |
Correct |
266 ms |
30964 KB |
Output is correct |
23 |
Correct |
213 ms |
30964 KB |
Output is correct |
24 |
Correct |
301 ms |
30964 KB |
Output is correct |
25 |
Correct |
192 ms |
30964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
30964 KB |
Output isn't correct |
2 |
Incorrect |
21 ms |
30964 KB |
Output isn't correct |
3 |
Correct |
93 ms |
30996 KB |
Output is correct |
4 |
Correct |
134 ms |
32148 KB |
Output is correct |
5 |
Correct |
132 ms |
32148 KB |
Output is correct |
6 |
Correct |
444 ms |
50900 KB |
Output is correct |
7 |
Incorrect |
29 ms |
50900 KB |
Output isn't correct |
8 |
Incorrect |
25 ms |
50900 KB |
Output isn't correct |
9 |
Correct |
24 ms |
50900 KB |
Output is correct |
10 |
Correct |
28 ms |
50900 KB |
Output is correct |
11 |
Correct |
25 ms |
50900 KB |
Output is correct |
12 |
Correct |
23 ms |
50900 KB |
Output is correct |
13 |
Correct |
21 ms |
50900 KB |
Output is correct |
14 |
Incorrect |
28 ms |
50900 KB |
Output isn't correct |
15 |
Incorrect |
25 ms |
50900 KB |
Output isn't correct |
16 |
Incorrect |
23 ms |
50900 KB |
Output isn't correct |
17 |
Correct |
31 ms |
50900 KB |
Output is correct |
18 |
Correct |
24 ms |
50900 KB |
Output is correct |
19 |
Correct |
21 ms |
50900 KB |
Output is correct |
20 |
Correct |
21 ms |
50900 KB |
Output is correct |
21 |
Correct |
21 ms |
50900 KB |
Output is correct |
22 |
Incorrect |
21 ms |
50900 KB |
Output isn't correct |
23 |
Incorrect |
82 ms |
50900 KB |
Output isn't correct |
24 |
Incorrect |
127 ms |
50900 KB |
Output isn't correct |
25 |
Correct |
125 ms |
50900 KB |
Output is correct |
26 |
Correct |
189 ms |
50900 KB |
Output is correct |
27 |
Correct |
100 ms |
50900 KB |
Output is correct |
28 |
Correct |
132 ms |
50900 KB |
Output is correct |
29 |
Correct |
365 ms |
50900 KB |
Output is correct |
30 |
Incorrect |
164 ms |
50900 KB |
Output isn't correct |
31 |
Incorrect |
162 ms |
50900 KB |
Output isn't correct |
32 |
Incorrect |
173 ms |
50900 KB |
Output isn't correct |
33 |
Correct |
142 ms |
50900 KB |
Output is correct |
34 |
Correct |
142 ms |
50900 KB |
Output is correct |
35 |
Correct |
144 ms |
50900 KB |
Output is correct |
36 |
Correct |
117 ms |
50900 KB |
Output is correct |
37 |
Correct |
327 ms |
51032 KB |
Output is correct |
38 |
Incorrect |
90 ms |
51032 KB |
Output isn't correct |
39 |
Incorrect |
94 ms |
51032 KB |
Output isn't correct |
40 |
Incorrect |
106 ms |
51032 KB |
Output isn't correct |
41 |
Correct |
100 ms |
51032 KB |
Output is correct |
42 |
Correct |
96 ms |
51032 KB |
Output is correct |
43 |
Correct |
123 ms |
51032 KB |
Output is correct |
44 |
Correct |
93 ms |
51032 KB |
Output is correct |
45 |
Correct |
374 ms |
51032 KB |
Output is correct |
46 |
Incorrect |
93 ms |
51032 KB |
Output isn't correct |
47 |
Incorrect |
90 ms |
51032 KB |
Output isn't correct |
48 |
Incorrect |
102 ms |
51032 KB |
Output isn't correct |
49 |
Correct |
90 ms |
51032 KB |
Output is correct |
50 |
Correct |
104 ms |
51032 KB |
Output is correct |
51 |
Correct |
147 ms |
51032 KB |
Output is correct |
52 |
Correct |
133 ms |
51032 KB |
Output is correct |
53 |
Correct |
328 ms |
51032 KB |
Output is correct |
54 |
Incorrect |
124 ms |
51032 KB |
Output isn't correct |