Submission #884422

# Submission time Handle Problem Language Result Execution time Memory
884422 2023-12-07T10:19:02 Z tsumondai Naboj (COCI22_naboj) C++14
0 / 110
91 ms 36912 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e6 + 5;
 
const int oo = 1e9, mod = 1e9 + 7;
 
int n, m, k;
int indegree[N], ans[N];
vector<int> adj[N];
vector<int> topo;
queue <int> listSource;

void process() {
	cin >> n >> n;
	foru(i,1,n) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
		indegree[v]++;
	}
	for (int u = 1; u <= n; ++u)
    	if (!indegree[u]) listSource.push(u);

    while (!listSource.empty()) {
    	int u = listSource.front();
    	listSource.pop();
    	topo.push_back(u);
    	for (auto v : adj[u]) {
    		indegree[v]--;
    		if (!indegree[v]) listSource.push(v);
    	}
    }

    if (topo.size() < n) {
    	cout << "-1";
    	return;
    }
    
    cout << topo.size() << '\n';
    for (auto x: topo) cout << x << ' ' << 0 << '\n';

    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

// dont stop

Compilation message

naboj.cpp: In function 'void process()':
naboj.cpp:47:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |     if (topo.size() < n) {
      |         ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 6 ms 27228 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 6 ms 27228 KB Output is correct
5 Correct 5 ms 27228 KB Output is correct
6 Correct 5 ms 27248 KB Output is correct
7 Correct 6 ms 27484 KB Output is correct
8 Incorrect 6 ms 27228 KB Integer parameter [name=c] equals to 11, violates the range [1, 10]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 36912 KB Output is correct
2 Incorrect 54 ms 35284 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 6 ms 27228 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 6 ms 27228 KB Output is correct
5 Correct 5 ms 27228 KB Output is correct
6 Correct 5 ms 27248 KB Output is correct
7 Correct 6 ms 27484 KB Output is correct
8 Incorrect 6 ms 27228 KB Integer parameter [name=c] equals to 11, violates the range [1, 10]
9 Halted 0 ms 0 KB -