제출 #884426

#제출 시각아이디문제언어결과실행 시간메모리
884426tsumondaiNaboj (COCI22_naboj)C++14
110 / 110
157 ms20208 KiB
#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 = 2e5 + 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 >> m;
	foru(i,1,m) {
		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

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...