Codeforces Gym100342J Triatrip
2015-08-07 10:34
639 查看
Problem J. Triatrip
Input file: triatrip.inOutput file: triatrip.out
Time limit: 3 seconds
Memory limit: 256 megabytes
The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way or roundtrip for airline tickets to their customers, “Four Russians” offers the brand new idea — triatrip. Triatrip raveler starts in some city A, flies to some city B, then flies to some city C, and returns to the city A.
Now the managers of the agency started to wonder, how many different triatrips they can offer to their customers. Given a map of all possible flights, help them to find that out.
Input
The first line of the input file contains two integer numbers n — the number of cities that are served by airlines that agree to sell their tickets via the agency (3 ≤ n ≤ 1500). The following n lines contain a sequence of n characters each — the j-th character of the i-th line is ‘+’ if it is possible to fly from the i-th city to the j-th one, and ‘-’ if it is not. The i-th character of the i-th line is ‘-’.Output
Output one integer number — the number of triatrips that the agency can offer to its customers.Example
triatrip.in4
–+-
+–+
-+–
–+-
triatrip.out
2
题意
一张有向图,求有多少个不同的三元环题解
用bitset暴力就行(读错题了以为就是找环,开心的wa了很久。。。)#include <cstdio> #include <cstdlib> #include <bitset> using namespace std; int n; char G[1505][1505]; bitset<1505> A[1505]; bitset<1505> B[1505]; long long ans=0; int main() { freopen("triatrip.in","r",stdin); freopen("triatrip.out","w",stdout); scanf("%d",&n); for(int i=0;i<n;i++) scanf("%s",G[i]); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(G[i][j]=='+') A[i][j]=B[j][i]=1; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(A[i][j]) ans+=(A[j]&B[i]).count(); } } printf("%I64d\n",ans/3); return 0; }
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B
- Codeforces Gym100571A Cursed Query
- Codeforces Gym100342E Minima
- Codeforces Div2 244AB
- Coder-Strike 2014 - Finals (online edition, Div. 2)AB
- Codeforces Div2 243AB