HDU-6073 Matching In Multiplication(拓扑+dfs)
来源:互联网 发布:中国知网数据库查重 编辑:程序博客网 时间:2024/06/05 00:48
传送门:HDU-6073
xjb拓扑一下把只有一条边的点去掉,然后dfs一下就行,中间TLE到怀疑人生,重写一遍就AC了,现在已经不想知道到底哪有问题了
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int mod = 998244353;const int MX = 300000 + 10;struct Edge { int nxt, v, w; bool vis;} E[MX * 4];int T, n, head[MX * 2], tot, IN[MX * 2], vis[MX * 2];LL val[2], ans;void add(int u, int v, int w) { E[tot].v = v; E[tot].w = w; E[tot].vis = 0; E[tot].nxt = head[u]; head[u] = tot++; IN[v]++;}void dfs(int u, int idx) { vis[u] = 1; for (int i = head[u]; i; i = E[i].nxt) { if (E[i].vis) continue; E[i].vis = E[i ^ 1].vis = 1; val[idx] = val[idx] * E[i].w % mod; dfs(E[i].v, 1 ^ idx); }}void top_sort() { queue<int> q; for (int v = n + 1; v <= n + n; v++) if (IN[v] == 1) q.push(v); while (!q.empty()) { int v = q.front(); q.pop(); vis[v] = 1; for (int i = head[v]; i; i = E[i].nxt) { if (E[i].vis) continue; E[i].vis = E[i ^ 1].vis = 1; vis[ E[i].v ] = 1; ans = ans * E[i].w % mod; for (int j = head[ E[i].v ]; j; j = E[j].nxt) { E[j].vis = E[j ^ 1].vis = 1; IN[E[j].v]--; if (IN[ E[j].v ] == 1) q.push(E[j].v); } } }}void solve() { ans = 1; top_sort(); for (int u = 1; u <= n; u++) { if (vis[u]) continue; val[0] = val[1] = 1; dfs(u, 0); ans = ans * (val[0] + val[1]) % mod; }}int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); memset(head, 0, sizeof(head)); memset(IN, 0, sizeof(IN)); memset(vis, 0, sizeof(vis)); tot = 0; for (int u = 1, v, w; u <= n; u++) for (int i = 0; i < 2; i++) { scanf("%d %d", &v, &w); add(u, v + n, w); add(v + n, u, w); } solve(); printf("%lld\n", ans); }}
阅读全文
0 0
- HDU-6073 Matching In Multiplication(拓扑+dfs)
- 【多校训练】hdu 6073 Matching In Multiplication. 拓扑+dfs
- HDU 6073 Matching In Multiplication (拓扑+DFS, 2017 Multi-Univ Training Contest 4)
- HDU 6073 Matching In Multiplication(强连通+拓扑)
- HDU 6073 Matching In Multiplication 思维(拓扑)
- HDU 6073 Matching In Multiplication(拓扑+思维)
- hdu 6073 Matching In Multiplication [dfs]
- 2017多校第4场 HDU 6073 Matching In Multiplication 拓扑排序,思维,DFS
- hdu 6073 Matching In Multiplication(无向图+拓扑排序+dfs找环)
- HDU 6073 Matching In Multiplication(机智)
- Matching In Multiplication(HDU 6073)
- HDU 6073 Matching In Multiplication
- HDU 6073 Matching In Multiplication
- HDU-6073 Matching In Multiplication
- hdu 6073 Matching In Multiplication
- HDU_6073 Matching In Multiplication 【二分图&&拓扑排序&&DFS】
- HDU6073 Matching In Multiplication【拓扑】
- Matching In Multiplication HDU
- (4)2017.8.4-java基础语法和控制流程(中)
- fluent nhibernate映射的数值类型问题
- SpringBoot-创建RESTful风格的 http接口访问jpa 来操作数据库
- spingMVC网页报“400”错误原因
- 沃顿商学院自我管理课
- HDU-6073 Matching In Multiplication(拓扑+dfs)
- 动态代理技术在JavaWeb中的应用
- 暑假多校联盟(=) e题 书架
- P3144 [USACO16OPEN]关闭农场Closing the Farm
- Python-栈
- web自动化测试第12步:selenium中下拉框的解决方法(Select)
- More is better HDU
- MySql主从同步和延迟同步
- 2017.8.4——。。。。。