- 家族
- 2016-06-27 21:27:43 @
记录信息
评测状态 Time Limit Exceeded
题目 P1034 家族
递交时间 2016-06-27 21:17:45
代码语言 C++
评测机 ShadowShore
消耗时间 6510 ms
消耗内存 24976 KiB
评测时间 2016-06-27 21:17:52
评测结果
编译成功
测试数据 #0: Accepted, time = 15 ms, mem = 24972 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 24972 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 24976 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 24972 KiB, score = 10
测试数据 #4: TimeLimitExceeded, time = 1187 ms, mem = 24964 KiB, score = 0
测试数据 #5: TimeLimitExceeded, time = 1203 ms, mem = 24968 KiB, score = 0
测试数据 #6: TimeLimitExceeded, time = 1015 ms, mem = 24964 KiB, score = 0
测试数据 #7: TimeLimitExceeded, time = 1015 ms, mem = 24968 KiB, score = 0
测试数据 #8: TimeLimitExceeded, time = 1015 ms, mem = 24968 KiB, score = 0
测试数据 #9: TimeLimitExceeded, time = 1015 ms, mem = 24968 KiB, score = 0
TimeLimitExceeded, time = 6510 ms, mem = 24976 KiB, score = 40
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using std :: min;
bool v[5001][5001];
int n,m,p;
void flyd() {
for (int k = 1;k <= n;k++)
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
if (v[i][k] && v[k][j]) v[i][j] = v[j][i] = true;
}
int main() {
memset(v,false,sizeof(v));
scanf("%d%d%d",&n,&m,&p);
for (int i = 1,a,b;i <= m;i++) {
scanf("%d%d",&a,&b);
v[a][b] = v[b][a] = true;
}
flyd();
for (int i = 1,a,b;i <= p;i++) {
scanf("%d%d",&a,&b);
if (v[a][b])
printf("Yes\n");
else
printf("No\n");
}
//system("pause");
return 0;
}
3 条评论
-
lrj124 LV 10 @ 2016-07-03 14:39:11
记录信息 评测状态 Accepted 题目 P1034 家族 递交时间 2016-07-03 14:38:32 代码语言 C++ 评测机 ShadowShore 消耗时间 61 ms 消耗内存 528 KiB 评测时间 2016-07-03 14:38:34 评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 524 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 524 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 524 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #6: Accepted, time = 15 ms, mem = 528 KiB, score = 10 测试数据 #7: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #8: Accepted, time = 31 ms, mem = 520 KiB, score = 10 测试数据 #9: Accepted, time = 15 ms, mem = 524 KiB, score = 10 Accepted, time = 61 ms, mem = 528 KiB, score = 100 代码 #include <cstdio> int f[5001],n,m,p; int find(int x) { if (f[x] != x) f[x] = find(f[x]); return f[x]; } int main() { scanf("%d%d%d",&n,&m,&p); for (int i = 1;i <= n;i++) f[i] = i; for (int i = 1,a,b;i <= m;i++) { scanf("%d%d",&a,&b); f[find(a)] = find(b); } for (int i = 1,a,b;i <= p;i++) { scanf("%d%d",&a,&b); if (find(a) == find(b)) printf("Yes\n"); else printf("No\n"); } return 0; }
-
2016-07-01 20:45:24@
// input code here ```太聪明·
-
2016-06-28 17:03:59@
用并查集吧
- 1