Submission #207365

# Submission time Handle Problem Language Result Execution time Memory
207365 2020-03-07T10:33:47 Z dolphingarlic Pipes (BOI13_pipes) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i <y;i++)
using namespace std;int n,m;set<pair<int,int>>g[6e5];int c[6e5],A[6e5],V[6e5],S=0;void d(int q,int z=1){V[q]=z;for(pair<int,int>i :g[q])if(!V[i.first]){d(i.first,3 - z);if(z == 1)S+=c[i.first];else S-=c[i.first];}}void p(){queue<int>L;FOR(i,1,n+1)if(g[i].size()== 1)L.push(i);while(L.size()){int O=L.front();L.pop();for(pair<int,int>i :g[O]){g[i.first].erase({O,i.second});A[i.second]=2*c[O];c[i.first]-=c[O];if(g[i.first].size()== 1)L.push(i.first);}g[O].clear();}}int main(){cin>>n>>m;FOR(i,1,n+1)cin>>c[i];FOR(i,1,m+1){int x,y;cin>>x>>y;g[x].insert({y,i});g[y].insert({x,i});}p();int cnt=0;FOR(i,1,n+1){if(g[i].size()>2)return cout<<0,0;if(g[i].size()== 2)cnt++;}if(cnt != 0 && !(cnt & 1))return cout<<0,0;FOR(i,1,n+1)if(g[i].size()== 2){d(i);int x=(*g[i].begin()).first,y=(*g[i].begin()).second;A[y]=c[i]+S;g[i].erase({x,y});g[x].erase({i,y});c[i]-=A[y]/2;c[x]-=A[y]/2;break;}p();FOR(i,1,m+1)cout<<A[i]<<'\n';return 0;}

Compilation message

pipes.cpp:3:52: error: size of array 'g' has non-integral type 'double'
 using namespace std;int n,m;set<pair<int,int>>g[6e5];int c[6e5],A[6e5],V[6e5],S=0;void d(int q,int z=1){V[q]=z;for(pair<int,int>i :g[q])if(!V[i.first]){d(i.first,3 - z);if(z == 1)S+=c[i.first];else S-=c[i.first];}}void p(){queue<int>L;FOR(i,1,n+1)if(g[i].size()== 1)L.push(i);while(L.size()){int O=L.front();L.pop();for(pair<int,int>i :g[O]){g[i.first].erase({O,i.second});A[i.second]=2*c[O];c[i.first]-=c[O];if(g[i.first].size()== 1)L.push(i.first);}g[O].clear();}}int main(){cin>>n>>m;FOR(i,1,n+1)cin>>c[i];FOR(i,1,m+1){int x,y;cin>>x>>y;g[x].insert({y,i});g[y].insert({x,i});}p();int cnt=0;FOR(i,1,n+1){if(g[i].size()>2)return cout<<0,0;if(g[i].size()== 2)cnt++;}if(cnt != 0 && !(cnt & 1))return cout<<0,0;FOR(i,1,n+1)if(g[i].size()== 2){d(i);int x=(*g[i].begin()).first,y=(*g[i].begin()).second;A[y]=c[i]+S;g[i].erase({x,y});g[x].erase({i,y});c[i]-=A[y]/2;c[x]-=A[y]/2;break;}p();FOR(i,1,m+1)cout<<A[i]<<'\n';return 0;}
                                                    ^
pipes.cpp:3:63: error: size of array 'c' has non-integral type 'double'
 using namespace std;int n,m;set<pair<int,int>>g[6e5];int c[6e5],A[6e5],V[6e5],S=0;void d(int q,int z=1){V[q]=z;for(pair<int,int>i :g[q])if(!V[i.first]){d(i.first,3 - z);if(z == 1)S+=c[i.first];else S-=c[i.first];}}void p(){queue<int>L;FOR(i,1,n+1)if(g[i].size()== 1)L.push(i);while(L.size()){int O=L.front();L.pop();for(pair<int,int>i :g[O]){g[i.first].erase({O,i.second});A[i.second]=2*c[O];c[i.first]-=c[O];if(g[i.first].size()== 1)L.push(i.first);}g[O].clear();}}int main(){cin>>n>>m;FOR(i,1,n+1)cin>>c[i];FOR(i,1,m+1){int x,y;cin>>x>>y;g[x].insert({y,i});g[y].insert({x,i});}p();int cnt=0;FOR(i,1,n+1){if(g[i].size()>2)return cout<<0,0;if(g[i].size()== 2)cnt++;}if(cnt != 0 && !(cnt & 1))return cout<<0,0;FOR(i,1,n+1)if(g[i].size()== 2){d(i);int x=(*g[i].begin()).first,y=(*g[i].begin()).second;A[y]=c[i]+S;g[i].erase({x,y});g[x].erase({i,y});c[i]-=A[y]/2;c[x]-=A[y]/2;break;}p();FOR(i,1,m+1)cout<<A[i]<<'\n';return 0;}
                                                               ^
pipes.cpp:3:70: error: size of array 'A' has non-integral type 'double'
 using namespace std;int n,m;set<pair<int,int>>g[6e5];int c[6e5],A[6e5],V[6e5],S=0;void d(int q,int z=1){V[q]=z;for(pair<int,int>i :g[q])if(!V[i.first]){d(i.first,3 - z);if(z == 1)S+=c[i.first];else S-=c[i.first];}}void p(){queue<int>L;FOR(i,1,n+1)if(g[i].size()== 1)L.push(i);while(L.size()){int O=L.front();L.pop();for(pair<int,int>i :g[O]){g[i.first].erase({O,i.second});A[i.second]=2*c[O];c[i.first]-=c[O];if(g[i.first].size()== 1)L.push(i.first);}g[O].clear();}}int main(){cin>>n>>m;FOR(i,1,n+1)cin>>c[i];FOR(i,1,m+1){int x,y;cin>>x>>y;g[x].insert({y,i});g[y].insert({x,i});}p();int cnt=0;FOR(i,1,n+1){if(g[i].size()>2)return cout<<0,0;if(g[i].size()== 2)cnt++;}if(cnt != 0 && !(cnt & 1))return cout<<0,0;FOR(i,1,n+1)if(g[i].size()== 2){d(i);int x=(*g[i].begin()).first,y=(*g[i].begin()).second;A[y]=c[i]+S;g[i].erase({x,y});g[x].erase({i,y});c[i]-=A[y]/2;c[x]-=A[y]/2;break;}p();FOR(i,1,m+1)cout<<A[i]<<'\n';return 0;}
                                                                      ^
pipes.cpp:3:77: error: size of array 'V' has non-integral type 'double'
 using namespace std;int n,m;set<pair<int,int>>g[6e5];int c[6e5],A[6e5],V[6e5],S=0;void d(int q,int z=1){V[q]=z;for(pair<int,int>i :g[q])if(!V[i.first]){d(i.first,3 - z);if(z == 1)S+=c[i.first];else S-=c[i.first];}}void p(){queue<int>L;FOR(i,1,n+1)if(g[i].size()== 1)L.push(i);while(L.size()){int O=L.front();L.pop();for(pair<int,int>i :g[O]){g[i.first].erase({O,i.second});A[i.second]=2*c[O];c[i.first]-=c[O];if(g[i.first].size()== 1)L.push(i.first);}g[O].clear();}}int main(){cin>>n>>m;FOR(i,1,n+1)cin>>c[i];FOR(i,1,m+1){int x,y;cin>>x>>y;g[x].insert({y,i});g[y].insert({x,i});}p();int cnt=0;FOR(i,1,n+1){if(g[i].size()>2)return cout<<0,0;if(g[i].size()== 2)cnt++;}if(cnt != 0 && !(cnt & 1))return cout<<0,0;FOR(i,1,n+1)if(g[i].size()== 2){d(i);int x=(*g[i].begin()).first,y=(*g[i].begin()).second;A[y]=c[i]+S;g[i].erase({x,y});g[x].erase({i,y});c[i]-=A[y]/2;c[x]-=A[y]/2;break;}p();FOR(i,1,m+1)cout<<A[i]<<'\n';return 0;}
                                                                             ^