| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
AC代码[code=cpp]#include <cstdio>
#include <algorithm>
//#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
const int M = 1000000 + 5;
int cnt, head[M], nxt[M], to[M];
void AddEdge(int u, int v) {
nxt[++cnt] = head[u], head[u] = cnt, to[cnt] = v;
}
int idx, num, top, dfn[M], low[M], s[M], sccno[M];
void Tarjan(int u) {
dfn[u] = low[u] = ++idx;
s[++top] = u;
for (int e = head[u]; e; e = nxt[e]) {
int v = to[e];
if (!dfn[v]) {
Tarjan(v);
low[u] = min(low[u], low[v]);
} else if (!sccno[v]) low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u]) {
num++;
while (1) {
int x = s[top--];
sccno[x] = num;
if (x == u) break;
}
}
}
int n, m, a[M], b[M];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d", &a[i], &b[i]);
if (a[i] > b[i]) swap(a[i], b[i]);
}
for (int i = 0; i < m; i++)
for (int j = i + 1; j < m; j++)
if (a[i] < a[j] && b[i] > a[j] && b[i] < b[j] || a[i] > a[j] && a[i] < b[j] && b[i] > b[j]) {
AddEdge(i << 1, (j << 1) | 1);
AddEdge((i << 1) | 1, j << 1);
AddEdge(j << 1, (i << 1) | 1);
AddEdge((j << 1) | 1, i << 1);
}
for (int i = 0; i < (m << 1); i++)
if (!dfn[i]) Tarjan(i);
for (int i = 0; i < (m << 1); i += 2)
if (sccno[i] == sccno[i ^ 1]) {
printf("the evil panda is lying again");
return 0;
}
printf("panda is telling the truth...");
return 0;
}[/code]
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator