bzoj 1059 1191 1433 1509 1854 2438 3436
parent
b629967b50
commit
083fa23f2e
@ -0,0 +1,31 @@
|
||||
#include <cstdio>
|
||||
int T, n, tmp, g[205][205], st, vis[205], pre[205];
|
||||
bool dfs(int u)
|
||||
{
|
||||
for (int v = 1; v <= n; v++) if (g[u][v]) if (vis[v] != st)
|
||||
{
|
||||
vis[v] = st;
|
||||
if (pre[v] == 0 || dfs(pre[v]))
|
||||
{
|
||||
pre[v] = u;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d", &T);
|
||||
while (T--)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++)
|
||||
scanf("%d", &g[i][j]);
|
||||
tmp = n;
|
||||
for (int i = 1; i <= n; i++) pre[i] = vis[i] = 0;
|
||||
for (st = 1; st <= n; st++) tmp -= dfs(st);
|
||||
puts(tmp ? "No" : "Yes");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
#include <cstdio>
|
||||
int head[1001], next[1001 << 1], to[1001 << 1], ecnt, ts;
|
||||
int vis[1001], pre[1001];
|
||||
inline void addEdge(int f, int t)
|
||||
{
|
||||
ecnt++;
|
||||
next[ecnt] = head[f];
|
||||
head[f] = ecnt;
|
||||
to[ecnt] = t;
|
||||
}
|
||||
bool dfs(int u)
|
||||
{
|
||||
for (int cur = head[u], v; cur; cur = next[cur])
|
||||
if (vis[to[cur]] != ts)
|
||||
{
|
||||
v = to[cur], vis[v] = ts;
|
||||
if (!pre[v] || dfs(pre[v]))
|
||||
{
|
||||
pre[v] = u;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1, x, y; i <= m; i++)
|
||||
{
|
||||
scanf("%d%d", &x, &y);
|
||||
addEdge(i, x);
|
||||
addEdge(i, y);
|
||||
}
|
||||
for (ts = 1; ts <= m + 1; ts++)
|
||||
if (!dfs(ts)) break;
|
||||
printf("%d", ts - 1);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
inline int readInt(int &x)
|
||||
{
|
||||
int ch = x = 0;
|
||||
while (!isdigit(ch = getchar()));
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x;
|
||||
}
|
||||
int T, n, tmp, g[55][55], b[55], c[55], st, vis[55], pre[55];
|
||||
bool dfs(int u)
|
||||
{
|
||||
for (int v = 1; v <= n; v++) if (g[u][v]) if (vis[v] != st)
|
||||
{
|
||||
vis[v] = st;
|
||||
if (pre[v] == 0 || dfs(pre[v]))
|
||||
{
|
||||
pre[v] = u;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
readInt(T);
|
||||
while (T--)
|
||||
{
|
||||
readInt(n);
|
||||
for (int i = 1; i <= n; i++) readInt(b[i]);
|
||||
for (int i = 1; i <= n; i++) readInt(c[i]);
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= n; j++)
|
||||
{
|
||||
readInt(tmp);
|
||||
g[i][j] = ((i == j && b[i] == 1 && c[i] == 0) || ((b[i] == 0 || (b[i] == 1 && c[i] == 0)) && tmp && b[j] == 1));
|
||||
}
|
||||
tmp = 0;
|
||||
for (int i = 1; i <= n; i++) pre[i] = vis[i] = 0;
|
||||
for (int i = 1; i <= n; i++) if (b[i] == 0 || (b[i] == 1 && c[i] == 0)) tmp++;
|
||||
for (st = 1; st <= n; st++) tmp -= dfs(st);
|
||||
puts(tmp ? "T_T" : "^_^");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
template <typename T> inline T max(T a, T b) { return a > b ? a : b; }
|
||||
template <typename T> inline T min(T a, T b) { return a < b ? a : b; }
|
||||
int head[200005], next[200005 << 2], to[200005 << 2], len[200005 << 2], ecnt, n, m, que[200005 << 1];
|
||||
long long disa[200005], disb[200005];
|
||||
inline void addEdge(int f, int t, int l)
|
||||
{
|
||||
ecnt++;
|
||||
next[ecnt] = head[f];
|
||||
head[f] = ecnt;
|
||||
to[ecnt] = t;
|
||||
len[ecnt] = l;
|
||||
}
|
||||
int bfs(int s, long long *dis)
|
||||
{
|
||||
int h = 0, t = 0;
|
||||
dis[s] = 0;
|
||||
que[t++] = s;
|
||||
for (int x; h != t; h++)
|
||||
for (int cur = head[x = que[h]]; cur; cur = next[cur])
|
||||
if (dis[to[cur]] == -1)
|
||||
dis[que[t++] = to[cur]] = dis[x] + len[cur];
|
||||
int id = -1; long long val = -1;
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (dis[i] > val) val = dis[id = i];
|
||||
return id;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 0, x, y, z; i < m; i++)
|
||||
{
|
||||
scanf("%d%d%d", &x, &y, &z);
|
||||
addEdge(x, y, z);
|
||||
addEdge(y, x, z);
|
||||
}
|
||||
memset(disa, -1, sizeof(disa));
|
||||
memset(disb, -1, sizeof(disb));
|
||||
int a = bfs(1, disa);
|
||||
memset(disa, -1, sizeof(disa));
|
||||
int b = bfs(a, disa);
|
||||
bfs(b, disb);
|
||||
long long ans = 0;
|
||||
for (int i = 1; i <= n; i++) ans = max(ans, min(disa[i], disb[i]));
|
||||
ans += disb[a];
|
||||
printf("%lld", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
#include <cstdio>
|
||||
int head[10010], next[2000010], to[2000010], ecnt, ts;
|
||||
int vis[1000010], pre[1000010];
|
||||
inline void addEdge(int f, int t)
|
||||
{
|
||||
ecnt++;
|
||||
next[ecnt] = head[f];
|
||||
head[f] = ecnt;
|
||||
to[ecnt] = t;
|
||||
}
|
||||
bool dfs(int u)
|
||||
{
|
||||
for (int cur = head[u], v; cur; cur = next[cur])
|
||||
if (vis[to[cur]] != ts)
|
||||
{
|
||||
v = to[cur], vis[v] = ts;
|
||||
if (!pre[v] || dfs(pre[v]))
|
||||
{
|
||||
pre[v] = u;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1, x, y; i <= n; i++)
|
||||
{
|
||||
scanf("%d%d", &x, &y);
|
||||
addEdge(x, i);
|
||||
addEdge(y, i);
|
||||
}
|
||||
for (ts = 1; ts <= 10001; ts++)
|
||||
if (!dfs(ts)) break;
|
||||
printf("%d", ts - 1);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
#include <cstdio>
|
||||
inline int min(int a, int b) { return a < b ? a : b; }
|
||||
int n, m, head[100010], next[300010], to[300010], ecnt,
|
||||
scc[100010], scccnt, st[100010], top, dfn[100010], low[100010], idx,
|
||||
nHead[100010], nNext[300010], nTo[300010], nEcnt, in[100010], sccsz[100010];
|
||||
bool instack[100010];
|
||||
inline void addEdge(int f, int t)
|
||||
{
|
||||
ecnt++;
|
||||
next[ecnt] = head[f];
|
||||
head[f] = ecnt;
|
||||
to[ecnt] = t;
|
||||
}
|
||||
inline void addEdgeN(int f, int t)
|
||||
{
|
||||
nEcnt++;
|
||||
nNext[nEcnt] = nHead[f];
|
||||
nHead[f] = nEcnt;
|
||||
nTo[nEcnt] = t;
|
||||
}
|
||||
void tarjan(int u)
|
||||
{
|
||||
dfn[u] = low[u] = ++idx;
|
||||
instack[st[top++] = u] = true;
|
||||
for (int cur = head[u]; cur; cur = next[cur])
|
||||
if (!dfn[to[cur]]) tarjan(to[cur]), low[u] = min(low[u], low[to[cur]]);
|
||||
else if (instack[to[cur]])
|
||||
low[u] = min(low[u], dfn[to[cur]]);
|
||||
if (dfn[u] == low[u])
|
||||
{
|
||||
scccnt++;
|
||||
do
|
||||
{
|
||||
top--;
|
||||
scc[st[top]] = scccnt;
|
||||
instack[st[top]] = false;
|
||||
sccsz[scccnt]++;
|
||||
} while (st[top] != u);
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1, x, y; i <= m; i++)
|
||||
{
|
||||
scanf("%d%d", &x, &y);
|
||||
addEdge(x, y);
|
||||
}
|
||||
for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i);
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int cur = head[i]; cur; cur = next[cur])
|
||||
if (scc[i] != scc[to[cur]])
|
||||
addEdgeN(scc[i], scc[to[cur]]), in[scc[to[cur]]]++;
|
||||
int cnt = 0;
|
||||
for (int i = 1; i <= scccnt; i++) if (in[i] == 0) cnt++;
|
||||
for (int i = 1; i <= scccnt; i++)
|
||||
if (sccsz[i] == 1 && in[i] == 0)
|
||||
{
|
||||
bool flag = true;
|
||||
for (int j = nHead[i]; j; j = nNext[j])
|
||||
if (in[nTo[j]] <= 1) { flag = false; break; }
|
||||
if (flag) { cnt--; break; }
|
||||
}
|
||||
printf("%.6lf", 1.0 * (n - cnt) / n);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
int head[10010], next[10010], to[10010], len[10010], ecnt, n, m, dis[10010];
|
||||
bool flag, inq[10010];
|
||||
inline void addEdge(int f, int t, int l)
|
||||
{
|
||||
ecnt++;
|
||||
next[ecnt] = head[f];
|
||||
head[f] = ecnt;
|
||||
to[ecnt] = t;
|
||||
len[ecnt] = l;
|
||||
}
|
||||
void dfs(int x)
|
||||
{
|
||||
if (flag) return;
|
||||
inq[x] = true;
|
||||
for (int cur = head[x]; cur; cur = next[cur])
|
||||
if (dis[to[cur]] > dis[x] + len[cur])
|
||||
{
|
||||
dis[to[cur]] = dis[x] + len[cur];
|
||||
if (!inq[to[cur]]) dfs(to[cur]);
|
||||
else { flag = true; return; }
|
||||
}
|
||||
inq[x] = false;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
memset(dis, 0x3f3f3f3f, sizeof(dis));
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 0, op, x, y, z; i < m; i++)
|
||||
{
|
||||
scanf("%d%d%d", &op, &x, &y);
|
||||
if (op == 1) scanf("%d", &z), addEdge(x, y, -z);
|
||||
if (op == 2) scanf("%d", &z), addEdge(y, x, z);
|
||||
if (op == 3) addEdge(x, y, 0);
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
dis[i] = 0, dfs(i);
|
||||
puts(flag ? "No" : "Yes");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue