8000 solved 0x1A 2252 · jo0n-lab/basic-algo-lecture@3e2ba4e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e2ba4e

Browse files
author
cuberry
committed
solved 0x1A 2252
1 parent 270bc2d commit 3e2ba4e

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed
File renamed without changes.

0x1A/v2252/main

37.2 KB
Binary file not shown.

0x1A/v2252/main.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define __INPUT__
5+
#define __DEBUG__
6+
#define __PRINT__
7+
8+
int N, M;
9+
vector<int> adj[100'002];
10+
int indeg[100'002];
11+
12+
int main() {
13+
ios::sync_with_stdio(false);
14+
cin.tie(NULL);
15+
16+
cin >> N >> M;
17+
for (int i = 1; i <= M; i++) {
18+
int u, v;
19+
cin >> u >> v;
20+
indeg[v]++;
21+
adj[u].push_back(v);
22+
}
23+
24+
queue<int> q;
25+
for (int i = 1; i <= N; i++) {
26+
if (indeg[i] == 0)
27+
q.push(i);
28+
}
29+
30+
while (!q.empty()) {
31+
int cur = q.front();
32+
q.pop();
33+
cout << cur << " ";
34+
int adj_s = adj[cur].size();
35+
for (int i = 0; i < adj_s; i++) {
36+
int next = adj[cur][i];
37+
if (--indeg[next] == 0)
38+
q.push(next);
39+
}
40+
}
41+
}

0x1A/v2252/tc1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3 2
2+
1 3
3+
2 3

0x1A/v2252/tc2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
4 2
2+
4 2
3+
3 1

0 commit comments

Comments
 (0)
0