2 条题解
-
0
暴力出奇迹,搭配上O2轻松通过这道题
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 5; int n, m, u, v, w, ans; struct Node { int v, w; } ; struct P { int u, v, w; bool operator<(const P& other) const { return tie(u, v, w) < tie(other.u, other.v, other.w); } }; vector <Node> p[2005]; set <P> ma; int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1;ch=getchar();} while(ch>='0' && ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} return x*f; } int main() { n = read(); m = read(); while (m--) { u = read(); v = read(); w = read(); p[u].push_back({v, w}); ma.insert({u, v, w}); } for (int i = 1; i <= n; ++i) for (int j = 0; j < p[i].size(); ++j) { int b = p[i][j].v, c = p[i][j].w; for (int k = 0; k < p[b].size(); ++k) { int d = p[b][k].w; if (c != p[b][k].v) continue; if (ma.find({i, b, d}) != ma.end() && ma.find({i, c, d}) != ma.end()) ++ans; } } printf("%d", ans); return 0; }
信息
- ID
- 43
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 4
- 标签
- 递交数
- 744
- 已通过
- 95
- 上传者