結果
問題 | No.1507 Road Blocked |
ユーザー |
|
提出日時 | 2021-05-14 22:38:18 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 3,695 bytes |
コンパイル時間 | 3,789 ms |
使用メモリ | 19,496 KB |
最終ジャッジ日時 | 2022-11-25 19:49:15 |
合計ジャッジ時間 | 7,380 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
3,500 KB |
testcase_01 | AC | 2 ms
3,592 KB |
testcase_02 | AC | 2 ms
3,576 KB |
testcase_03 | AC | 39 ms
19,496 KB |
testcase_04 | AC | 50 ms
10,152 KB |
testcase_05 | AC | 49 ms
10,192 KB |
testcase_06 | AC | 47 ms
10,200 KB |
testcase_07 | AC | 48 ms
10,192 KB |
testcase_08 | AC | 50 ms
10,224 KB |
testcase_09 | AC | 49 ms
10,156 KB |
testcase_10 | AC | 50 ms
10,156 KB |
testcase_11 | AC | 53 ms
10,252 KB |
testcase_12 | AC | 47 ms
10,188 KB |
testcase_13 | AC | 46 ms
10,192 KB |
testcase_14 | AC | 51 ms
10,160 KB |
testcase_15 | AC | 47 ms
10,108 KB |
testcase_16 | AC | 53 ms
10,192 KB |
testcase_17 | AC | 58 ms
10,152 KB |
testcase_18 | AC | 48 ms
10,092 KB |
testcase_19 | AC | 55 ms
10,156 KB |
testcase_20 | AC | 51 ms
10,228 KB |
testcase_21 | AC | 61 ms
10,196 KB |
testcase_22 | AC | 55 ms
10,156 KB |
testcase_23 | AC | 50 ms
10,148 KB |
testcase_24 | AC | 62 ms
10,248 KB |
testcase_25 | AC | 57 ms
10,340 KB |
testcase_26 | AC | 54 ms
10,264 KB |
testcase_27 | AC | 51 ms
10,120 KB |
testcase_28 | AC | 60 ms
10,256 KB |
testcase_29 | AC | 55 ms
10,156 KB |
testcase_30 | AC | 56 ms
10,236 KB |
testcase_31 | AC | 49 ms
10,220 KB |
testcase_32 | AC | 53 ms
10,152 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; typedef pair<int,int> Pi; #define rep(i,n) for(ll i=0;i<n;i++) #define FOR(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,n) for(ll i=n-1;i>=0;i--) #define rFOR(i,a,b) for(ll i=a-1;i>=b;i--) #define all(x) (x).begin(),(x).end() #define fi first #define se second #define endl "\n" istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); } istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;} template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";} template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";} template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;} template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;} template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;} template<class T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } const ll mod=1'000'000'007; const ll inf=1'000'000'000'000'000'00; const int INF=1'000'000'000; const double EPS=1e-10; const double PI=acos(-1); using mint=modint998244353; struct combination{ vector<mint> fact,ifact; combination(int n):fact(n+1),ifact(n+1){ assert(n<mod); fact[0]=1; for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i; ifact[n]=fact[n].inv(); for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i; } mint operator()(int n,int k){ if (k<0 || k>n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; int main(){ cin.tie(0);ios::sync_with_stdio(false); int n; cin>>n; vector<vector<int>> g(n); rep(i,n-1){ int u,v; cin>>u>>v; u--,v--; g[u].push_back(v); g[v].push_back(u); } mint ans=0; vector<ll> dp(n); combination comb(n+1); auto dfs=[&](auto &&dfs,int v,int pre)->void{ for(auto &&to:g[v]){ if(to==pre) continue; dfs(dfs,to,v); dp[v]+=dp[to]; ans+=comb(dp[to],2); ans+=comb(n-dp[to],2); } dp[v]++; }; dfs(dfs,0,-1); ans/=(n-1); ans/=comb(n,2); cout<<ans<<endl; }