Submission #792322

# Submission time Handle Problem Language Result Execution time Memory
792322 2023-07-25T01:01:01 Z cig32 Naboj (COCI22_naboj) C++17
110 / 110
170 ms 33828 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
int n, m;
vector<int> adj[MAXN];
int K[MAXN];
bool vis[MAXN];
stack<int> topsort;
void dfs(int node) {
  vis[node] = 1;
  for(int x: adj[node]) {
    if(!vis[x]) {
      dfs(x);
    }
  }
  topsort.push(node);
}
void solve(int tc) {
  cin >> n >> m;
  vector<pair<int, int> > constraints;
  for(int i=1; i<=m; i++) {
    int a, b;
    cin >> a >> b;
    constraints.push_back({a, b});
    adj[b].push_back(a);
  }
  for(int i=1; i<=n; i++) {
    if(!vis[i]) {
      dfs(i);
    }
  }
  for(int i=1; i<=n; i++) {
    K[topsort.top()] = i;
    topsort.pop();
  }
  for(pair<int, int> X: constraints) {
    if(K[X.first] < K[X.second]) {
      cout << "-1\n"; return;
    }
  }
  int pos[n+1];
  for(int i=1; i<=n; i++) pos[K[i]] = i;
  cout << n << "\n";
  for(int i=1; i<=n; i++) {
    cout << pos[i] << " 1\n";
  }

}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 5028 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 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 5032 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 21732 KB Output is correct
2 Correct 69 ms 21788 KB Output is correct
3 Correct 33 ms 13684 KB Output is correct
4 Correct 79 ms 21720 KB Output is correct
5 Correct 69 ms 21760 KB Output is correct
6 Correct 78 ms 21808 KB Output is correct
7 Correct 70 ms 21808 KB Output is correct
8 Correct 59 ms 18028 KB Output is correct
9 Correct 79 ms 21680 KB Output is correct
10 Correct 77 ms 21768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 5028 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 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 5032 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 84 ms 21732 KB Output is correct
16 Correct 69 ms 21788 KB Output is correct
17 Correct 33 ms 13684 KB Output is correct
18 Correct 79 ms 21720 KB Output is correct
19 Correct 69 ms 21760 KB Output is correct
20 Correct 78 ms 21808 KB Output is correct
21 Correct 70 ms 21808 KB Output is correct
22 Correct 59 ms 18028 KB Output is correct
23 Correct 79 ms 21680 KB Output is correct
24 Correct 77 ms 21768 KB Output is correct
25 Correct 123 ms 28280 KB Output is correct
26 Correct 90 ms 23268 KB Output is correct
27 Correct 112 ms 27232 KB Output is correct
28 Correct 155 ms 33032 KB Output is correct
29 Correct 67 ms 20492 KB Output is correct
30 Correct 170 ms 32444 KB Output is correct
31 Correct 19 ms 9412 KB Output is correct
32 Correct 75 ms 24336 KB Output is correct
33 Correct 135 ms 32244 KB Output is correct
34 Correct 103 ms 24972 KB Output is correct
35 Correct 155 ms 32548 KB Output is correct
36 Correct 77 ms 24076 KB Output is correct
37 Correct 126 ms 30464 KB Output is correct
38 Correct 127 ms 28084 KB Output is correct
39 Correct 139 ms 31976 KB Output is correct
40 Correct 132 ms 29432 KB Output is correct
41 Correct 137 ms 29220 KB Output is correct
42 Correct 143 ms 33428 KB Output is correct
43 Correct 100 ms 25708 KB Output is correct
44 Correct 161 ms 33828 KB Output is correct
45 Correct 106 ms 24860 KB Output is correct
46 Correct 120 ms 29488 KB Output is correct