提出 #69496515
ソースコード 拡げる
/* Code By WCM */
/*
Date:
大致思路:
复杂度:
期望得分:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
inline int read();
void write(int);
void writeln(int);
const int N = 2e5 + 5;
int n, a[N], b[N], ans;
vector <int> G[N];
void dfs(int u) {
for(auto v : G[u]) {
if(a[v]) continue;
a[v] = 1, dfs(v);
}
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = read();
for(int i = 1; i <= n; i++) {
int u = read(), v = read();
G[u].pb(i), G[v].pb(i);
if(u == 0 && v == 0) b[i] = a[i] = 1;
}
for(int i = 1; i <= n; i++) if(b[i]) dfs(i);
for(int i = 1; i <= n; i++) ans += (a[i]);
printf("%d\n", ans);
// printf("\nThe time used: ");
// printf("%.2lfs",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
inline int read() {
int res = 0, f = 1;
char ch = getchar();
while( !(ch >= '0' && ch <= '9') ) {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
res = (res << 1) + (res << 3) + (ch ^ 48);
ch = getchar();
}
return res * f;
}
void write(int x) {
static int sta[35];
int top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top) putchar(sta[--top] ^ 48);
}
void writeln(int x) {
write(x);
putchar('\n');
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - New Skill Acquired |
| ユーザ | WZwangchongming |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 300 |
| コード長 | 1468 Byte |
| 結果 | AC |
| 実行時間 | 49 ms |
| メモリ | 18816 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, sample_01.txt, sample_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| hand_01.txt | AC | 2 ms | 3692 KiB |
| hand_02.txt | AC | 1 ms | 3704 KiB |
| random_01.txt | AC | 32 ms | 13952 KiB |
| random_02.txt | AC | 3 ms | 4244 KiB |
| random_03.txt | AC | 46 ms | 16912 KiB |
| random_04.txt | AC | 32 ms | 13360 KiB |
| random_05.txt | AC | 45 ms | 16812 KiB |
| random_06.txt | AC | 36 ms | 13612 KiB |
| random_07.txt | AC | 49 ms | 16828 KiB |
| random_08.txt | AC | 5 ms | 6344 KiB |
| random_09.txt | AC | 43 ms | 18772 KiB |
| random_10.txt | AC | 41 ms | 17664 KiB |
| random_11.txt | AC | 25 ms | 18816 KiB |
| random_12.txt | AC | 42 ms | 16720 KiB |
| random_13.txt | AC | 43 ms | 15832 KiB |
| random_14.txt | AC | 42 ms | 15728 KiB |
| random_15.txt | AC | 42 ms | 16060 KiB |
| random_16.txt | AC | 14 ms | 8316 KiB |
| random_17.txt | AC | 38 ms | 14704 KiB |
| random_18.txt | AC | 5 ms | 5120 KiB |
| random_19.txt | AC | 18 ms | 9248 KiB |
| random_20.txt | AC | 28 ms | 11948 KiB |
| random_21.txt | AC | 2 ms | 3920 KiB |
| random_22.txt | AC | 9 ms | 6340 KiB |
| random_23.txt | AC | 40 ms | 14352 KiB |
| random_24.txt | AC | 11 ms | 6992 KiB |
| random_25.txt | AC | 19 ms | 9484 KiB |
| random_26.txt | AC | 2 ms | 3840 KiB |
| sample_01.txt | AC | 2 ms | 3640 KiB |
| sample_02.txt | AC | 1 ms | 3656 KiB |