結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー | eQe |
提出日時 | 2023-08-08 16:32:39 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,391 bytes |
コンパイル時間 | 7,010 ms |
コンパイル使用メモリ | 325,792 KB |
実行使用メモリ | 28,724 KB |
最終ジャッジ日時 | 2024-11-08 23:17:30 |
合計ジャッジ時間 | 8,606 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 21 ms
6,272 KB |
testcase_05 | AC | 41 ms
9,088 KB |
testcase_06 | AC | 46 ms
9,984 KB |
testcase_07 | AC | 26 ms
7,168 KB |
testcase_08 | AC | 32 ms
7,808 KB |
testcase_09 | AC | 47 ms
9,984 KB |
testcase_10 | AC | 41 ms
9,344 KB |
testcase_11 | AC | 34 ms
8,320 KB |
testcase_12 | AC | 45 ms
9,856 KB |
testcase_13 | AC | 33 ms
8,064 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace atcoder; template<typename V>struct ve; using ml=modint;using m1=ve<ml>; auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();} #define eb(...) emplace_back(__VA_ARGS__) #define all(a) begin(a),end(a) #define eif(...) else if(__VA_ARGS__) #define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__) #define LL(...) RD(ll,__VA_ARGS__) #define JO(a,b) a##b #define jo(a,b) JO(a,b) #define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v) #define FO(n) for(ll jo(i,____LINE__)=n;jo(i,____LINE__)-->0;) #define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i<i##O;i+=i##E) #define fe(v,...) FE(v,__VA_ARGS__) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define I(...) template<__VA_ARGS__> #define J typename #define O operator #define au auto #define cs const #define ifc if constexpr #define rr return #define uu using uu std::cin,std::cout,std::begin,std::end,std::rbegin,std::get; uu std::swap,std::move,std::abs,std::prev,std::next; uu std::tuple,std::array,std::bitset,std::minmax; uu vo=void;uu bo=bool; vo solve(); I(J A,J B)constexpr bo same=std::is_same_v<A,B>; I(bo b,J A,J B)uu ift=std::conditional_t<b,A,B>; uu is=std::istream;uu os=std::ostream; uu dd=long double;uu ll=long long;uu ull=unsigned long long; uu lll=__int128_t;uu ulll=__uint128_t;uu str=std::string; dd ee=1e-12; ll oo=3e18; array<ll,8>dx{-1,0,1,0,-1,1,1,-1},dy{0,-1,0,1,-1,-1,1,1}; char sp=32; char nl=10; I(J T,ll n)au TP(){ifc(n)rr tuple_cat(tuple(T()),TP<T,n-1>());else rr tuple();} I(J T,ll n)uu tp=decltype(TP<T,n>());I(ll n)uu tpl=tp<ll,n>; au rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,a=0;rr tuple{a,b-s,c};} I(J T)T zz(T x){rr x<0?-x:x;} I(J T)ll len(cs T&a){rr a.size();} I(J...A)au max(cs A&...a){rr max(std::initializer_list<std::common_type_t<A...>>{a...});} struct edg{ ll t,w; edg(){} edg(ll t,ll w=1):t(t),w(w){} friend os&O<<(os&o,cs edg&e){rr o<<e.t<<sp<<e.w;} }; I(J A,J B=A)struct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(std::pair<A,B>p):a(p.first),b(p.second){} cp O-()cs{rr cp(-a,-b);} cp&O++(){rr*this+=1;} cp&O--(){rr*this+=1;} cp&O+=(cs cp&c){a+=c.a,b+=c.b;rr*this;}cp O+(cs cp&c)cs{rr cp(*this)+=c;} cp&O-=(cs cp&c){a-=c.a,b-=c.b;rr*this;}cp O-(cs cp&c)cs{rr cp(*this)-=c;} I(J T)cp&O+=(cs T&x){a+=x,b+=x;rr*this;}I(J T)cp O+(cs T&x)cs{rr cp(*this)+=x;} I(J T)cp&O-=(cs T&x){a-=x,b-=x;rr*this;}I(J T)cp O-(cs T&x)cs{rr cp(*this)-=x;} I(J T)cp&O*=(cs T&x){a*=x,b*=x;rr*this;}I(J T)cp O*(cs T&x)cs{rr cp(*this)*=x;} bo O==(cs cp&c)cs{rr a==c.a&&b==c.b;} bo O<(cs cp&c)cs{rr a!=c.a?a<c.a:b<c.b;} bo O>(cs cp&c)cs{rr a!=c.a?a>c.a:b>c.b;} friend is&O>>(is&i,cp&c){rr i>>c.a>>c.b;} friend os&O<<(os&o,cs cp&c){rr o<<c.a<<sp<<c.b;} };uu cl=cp<ll>; I(J A,J B=A,J C=A)struct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bo O==(cs tr&t)cs{rr a==t.a&&b==t.b&&c==t.c;} friend is&O>>(is&i,tr&t){rr i>>t.a>>t.b>>t.c;} friend os&O<<(os&o,cs tr&t){rr o<<t.a<<sp<<t.b<<sp<<t.c;} };uu tl=tr<ll>; I(J T)decltype(au)rb(T&a){rr*rbegin(a);} I(J T)au pot(T&a){au r=a.top();a.pop();rr r;} I(J V)struct ve; I(J V)constexpr bo isv=0; I(J V)constexpr bo isv<ve<V>> =1; I(J V)constexpr bo isv<std::vector<V>> =1; I(J V)au rawv(V){ifc(isv<V>)rr rawv(V(1)[0]);else rr V();} I(J V)struct ve:std::vector<V>{ uu std::vector<V>::vector; uu T=decltype(rawv(V())); I(J U)ve(cs std::vector<U>&v={}){fe(v,e)this->eb(e);} au&O+=(cs ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;} au&O-=(cs ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;} au&O^=(cs ve&u){fe(u,e)this->eb(e);rr*this;} au&O+=(cs T&x){au&v=*this;fe(v,e)e+=x;rr v;} au&O-=(cs T&x){au&v=*this;fe(v,e)e-=x;rr v;} au&O*=(cs T&x){au&v=*this;fe(v,e)e*=x;rr v;} I(size_t n)au&O+=(cs bitset<n>&a){fo(i,n)(*this)[i]+=a[i];rr*this;} I(size_t n)au&O-=(cs bitset<n>&a){fo(i,n)(*this)[i]-=a[i];rr*this;} au O+(cs ve&u){rr ve(*this)+=u;} au O-(cs ve&u){rr ve(*this)-=u;} au O^(cs ve&u){rr ve(*this)^=u;} au O+(cs T&x){rr ve(*this)+=x;}au&O++(){rr*this+=1;} au O-(cs T&x){rr ve(*this)-=x;}au&O--(){rr*this-=1;} au O*(cs T&x){rr ve(*this)*=x;}au O-(){rr ve(*this)*=-1;} au lower_bound(cs V&x){rr std::lower_bound(all(*this),x);} au upper_bound(cs V&x){rr std::upper_bound(all(*this),x);} ve sel(cs std::vector<T>&is){ve r;fe(is,i)r.eb((*this)[i]);rr r;} I(J F)au scan(F f){cp<T,bo>r;fe(*this,e)ifc(!isv<V>)r.b?f(r.a,e),r:r={e,1};eif(au s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;rr r;} T max(){rr scan([](T&a,cs T&b){a<b?a=b:0;}).a;} }; I(J T=ll,ll n,ll i=0)au vec(cs ll(&s)[n],T x={}){ifc(n==i+1)rr ve<T>(s[i],x);else{au X=vec<T,n,i+1>(s,x);rr ve<decltype(X)>(s[i],X);}} I(ll n,J...A)vo setsize(cs ll(&l)[n],A&...a){((a=vec(l,rawv(a))),...);} I(J T)uu V1=ve<T>;uu u1=V1<ll>;I(J T)uu V2=V1<V1<T>>;uu u2=V2<ll>; uu strs=V1<str>;uu gra=V2<edg>;uu cls=V1<cl>;uu tls=V1<tl>; struct io{io(){cin.tie(0)->sync_with_stdio(0); cout<<std::fixed<<std::setprecision(15);std::cerr<<nl;}}io; os&O<<(os&o,cs ulll&x){rr(x<10?o:o<<x/10)<<ll(x%10);} os&O<<(os&o,cs lll&x){rr o<<str(x<0,'-')<<ulll(zz(x));} I(size_t n)os&O<<(os&o,cs bitset<n>&b){fo(i,n)o<<b[i];rr o;} I(J...A)os&O<<(os&o,cs tuple<A...>&t){ apply([&](cs au&...a){ll i=0;(((o<<a<<str(++i!=sizeof...(a),sp))),...);},t);rr o;} I(J V)os&O<<(os&o,cs std::vector<V>&v){fe(v,e)o<<e<<str(&e!=&v.back(),isv<V>?nl:sp);rr o;} I(J...A)vo pp(cs A&...a){ll i=0;((cout<<a<<str(++i!=sizeof...(a),sp)),...);cout<<nl;} I(J V)is&O>>(is&i,std::vector<V>&v){fe(v,e)i>>e;rr i;} I(J...A)vo li(A&...a){(cin>>...>>a);} I(J...A)vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);} I(J G)au ygi(G&g,ll m=-1,bo f=1){if(m==-1)m=len(g)-1;ift<same<G,u2>,cls,tls>r(m);li(r); fe(r,e)ifc(same<G,u2>)g[e.a-=f].eb(e.b-=f);else g[e.a-=f].eb(e.b-=f,e.c);rr r;} int main(){ll T=1;fo(T)solve();} vo solve(){ LL(N,M); u2 g(N); au es=ygi(g,M); u1 dg(N); dsu uf(N); fe(es,a,b){ uf.merge(a,b); dg[a]--,dg[b]++; } u2 gs=uf.groups(); ll ans=0; ll C=0;//自己ループなしの孤立点以外の個数.自己ループなしの孤立点には辺がないので連結にする必要なし. fe(gs,v){ if(len(g[v[0]]))C++; u1 d=dg.sel(v); ll su=0; fe(d,x)if(x>0)su+=x; ans+=max(su-1,0); } ans+=C-1; pp(ans); }