답안 #704973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704973 2023-03-03T07:29:31 Z PikaQ Naboj (COCI22_naboj) C++17
110 / 110
910 ms 21780 KB
#include<bits/stdc++.h>
#define int long long
#define forn(i,n) for(int i = 0;i < n;i++)
#define Forn(i,n) for(int i = 1;i <= n;i++)
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
#define F first
#define S second
using namespace std;
void debug() {cerr << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cerr << a << " "; debug(b...);}
const int INF = 1e13 + 10;
const int MOD = (int) 998244353;
const int N = 2e5 + 9;
int n,m;
vi e[N];

int in[N];
vi ord;
bool tag[N],vis[N];

void dfs(int u){
	debug(u);
	vis[u] = 1,tag[u] = 1;
	for(int c : e[u]){
		if(tag[c]){
			cout << "-1\n";
			exit(0);
		}
		if(!vis[c]){
			dfs(c);
		}
	}
	tag[u] = 0;
	ord.pb(u);
}
bool st[N];

void solve(){
	//pancake ( ^-^)_	
	cin >> n >> m;
	forn(i,m){
		int s,t;
		cin >> s >> t;
		e[s].pb(t);
		in[t]++;
	}
	
	Forn(i,n){
		if(!vis[i] && in[i] == 0) dfs(i),st[i] = 1;
	}
	if(ord.size() != n) {
		cout << "-1\n";
		return;
	}
	cout << ord.size() << '\n';
	reverse(all(ord));
	for(auto &i : ord) {
		if(st[i]) cout << i << ' ' << 1 << '\n';
		else cout << i << ' ' << 0 << '\n';
	}
}

signed main(){
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(0);
	solve();
	return 0;
}







	

Compilation message

naboj.cpp: In function 'void solve()':
naboj.cpp:54:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   54 |  if(ord.size() != n) {
      |     ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 3 ms 5032 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5028 KB Output is correct
13 Correct 3 ms 4924 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 778 ms 18852 KB Output is correct
2 Correct 787 ms 18932 KB Output is correct
3 Correct 410 ms 12264 KB Output is correct
4 Correct 783 ms 19124 KB Output is correct
5 Correct 769 ms 18964 KB Output is correct
6 Correct 773 ms 19004 KB Output is correct
7 Correct 782 ms 18992 KB Output is correct
8 Correct 603 ms 15812 KB Output is correct
9 Correct 789 ms 18940 KB Output is correct
10 Correct 762 ms 18924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 3 ms 5032 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5028 KB Output is correct
13 Correct 3 ms 4924 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 778 ms 18852 KB Output is correct
16 Correct 787 ms 18932 KB Output is correct
17 Correct 410 ms 12264 KB Output is correct
18 Correct 783 ms 19124 KB Output is correct
19 Correct 769 ms 18964 KB Output is correct
20 Correct 773 ms 19004 KB Output is correct
21 Correct 782 ms 18992 KB Output is correct
22 Correct 603 ms 15812 KB Output is correct
23 Correct 789 ms 18940 KB Output is correct
24 Correct 762 ms 18924 KB Output is correct
25 Correct 139 ms 15768 KB Output is correct
26 Correct 117 ms 15168 KB Output is correct
27 Correct 138 ms 16228 KB Output is correct
28 Correct 174 ms 17656 KB Output is correct
29 Correct 90 ms 14576 KB Output is correct
30 Correct 174 ms 17440 KB Output is correct
31 Correct 21 ms 7340 KB Output is correct
32 Correct 791 ms 18640 KB Output is correct
33 Correct 879 ms 21648 KB Output is correct
34 Correct 798 ms 18868 KB Output is correct
35 Correct 881 ms 21564 KB Output is correct
36 Correct 774 ms 18040 KB Output is correct
37 Correct 853 ms 20644 KB Output is correct
38 Correct 841 ms 19716 KB Output is correct
39 Correct 890 ms 21248 KB Output is correct
40 Correct 875 ms 20468 KB Output is correct
41 Correct 864 ms 20300 KB Output is correct
42 Correct 908 ms 21560 KB Output is correct
43 Correct 800 ms 18748 KB Output is correct
44 Correct 910 ms 21780 KB Output is correct
45 Correct 822 ms 18396 KB Output is correct
46 Correct 880 ms 20388 KB Output is correct