#include #include using namespace std; using namespace atcoder; #define rep(i,n) for(int i=0;in; int m,ns=0; rep(i,3)cin>>n[i]; rep(i,3)ns+=n[i]; cin>>m; vectoru(m),v(m),st; rep(i,m){ cin>>u[i]>>v[i]; u[i]--;v[i]--; st.emplace_back(u[i]); st.emplace_back(v[i]); } st.emplace_back(ns); st.emplace_back(ns+1); sort(st.begin(),st.end()); st.erase(unique(st.begin(),st.end()),st.end()); int n2=st.size(); vector>> g(n2); scc_graph scc(n2); auto get=[&](int i){ return lower_bound(st.begin(),st.end(),i)-st.begin(); }; //cerr<=pre+n[i]){ g[n2-2].emplace_back(n2-1,n[i]+1); pre+=n[i]; continue; } g[n2-2].emplace_back(now,st[now]-pre+1); while(1){ if(st[now+1]-pre>=n[i])break; g[now].emplace_back(now+1,(st[now+1]-pre+1)-(st[now]-pre+1)); now++; } g[now].emplace_back(n2-1,(n[i]+1)-(st[now]-pre+1)); now++; pre+=n[i]; } } rep(i,m){ g[get(u[i])].emplace_back(get(v[i]),1); g[get(v[i])].emplace_back(get(u[i]),1); } rep(i,n2){ for(auto [e,c]:g[i]){ scc.add_edge(i,e); } } auto res=scc.scc(); int sz=res.size(); //cerr<>g2(sz); vectorid(n2); vectorv1(sz),v2(sz),v3(sz,1),v4(sz),v5(sz); rep(i,sz){ for(auto s:res[i]){ //cerr<