結果
問題 |
No.1147 土偶Ⅱ
|
ユーザー |
![]() |
提出日時 | 2020-08-07 15:39:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 500 ms |
コード長 | 1,360 bytes |
コンパイル時間 | 2,350 ms |
コンパイル使用メモリ | 199,668 KB |
最終ジャッジ日時 | 2025-01-12 15:45:15 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename TV, const int N> void read_tuple_impl(TV&) {} template<typename TV, const int N, typename Head, typename... Tail> void read_tuple_impl(TV& ts) { get<N>(ts).emplace_back(*(istream_iterator<Head>(cin))); read_tuple_impl<TV, N+1, Tail...>(ts); } template<typename... Ts> decltype(auto) read_tuple(size_t n) { tuple<vector<Ts>...> ts; for(size_t i=0;i<n;i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts); return ts; } //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; auto [as, bs]=read_tuple<int, int>(m); vector G(n,vector(n,n)); for(int i=0;i<n;i++) G[i][i]=0; for(int i=0;i<m;i++){ as[i]--;bs[i]--; G[as[i]][bs[i]]=1; G[bs[i]][as[i]]=1; } for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) chmin(G[i][j],G[i][k]+G[k][j]); int ans=0; for(int i=0;i<n;i++) for(int j=0;j<i;j++) for(int k=0;k<j;k++) if(G[i][j]!=2 and G[i][k]!=2 and G[j][k]!=2) ans++; cout<<ans<<newl; return 0; }