Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <cstdlib>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <map>
- #include <set>
- #include <cmath>
- #include <ctime>
- #include <cassert>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define sz(A) (int)(A).size()
- typedef long long LL;
- typedef long double LD;
- const int N = 205, M = 1005;
- vector<int> graph[N], ts, g[M], suf[N], num[N];
- bool dp[N][N], was[M], ok[N];
- int from[N][N], from_num[N][N], color[M], cur, n, m, t;
- void dfs(int v) {
- was[v] = 1;
- color[v] = cur;
- for (int i = 0; i < sz(graph[v]); i++) {
- int to = graph[v][i];
- if (!was[to])
- dfs(to);
- }
- ts.pb(v);
- }
- void dfs2(int v) {
- was[v] = 1;
- for (int i = 0; i < sz(g[v]); i++) {
- int to = g[v][i];
- if (!was[to])
- dfs2(to);
- }
- }
- int main()
- {
- freopen("suffix.in", "r", stdin);
- freopen("suffix.out", "w", stdout);
- cin >> n >> m >> t;
- for (int i = 0; i < t; i++) {
- int term;
- cin >> term;
- ok[term] = 1;
- }
- for (int i = 0; i < m; i++) {
- int s, t;
- cin >> s >> t;
- graph[s].pb(t);
- num[s].pb(i);
- }
- dfs(1);
- dp[1][0] = 1;
- for (int i = sz(ts) - 1; i >= 0; i--) {
- int v = ts[i];
- for (int j = 0; j < n; j++) {
- if (dp[v][j]) {
- for (int q = 0; q < sz(graph[v]); q++) {
- int to = graph[v][q];
- dp[to][j + 1] = 1;
- from[to][j + 1] = v;
- from_num[to][j + 1] = num[v][q];
- }
- }
- }
- }
- int mx = 0;
- for (int i = 1; i <= n; i++) {
- if (ok[i]) {
- for (int j = 0; j < n; j++) {
- if (dp[i][j]) {
- //cerr << i << " " << j << endl;
- mx = max(mx, j);
- int nowv = i;
- for (int k = j; k > 0; k--) {
- suf[j].pb(from_num[nowv][k]);
- nowv = from[nowv][k];
- }
- }
- }
- }
- }
- for (int i = 0; i < mx; i++) {
- for (int j = i + 1; j <= mx; j++) {
- g[ suf[i + 1][i] ].pb(suf[j][i]);
- g[ suf[j][i] ].pb(suf[i + 1][i]);
- fprintf(stderr, "%d - %d\n", suf[j][i], suf[i + 1][i]);
- }
- }
- memset(was, 0, sizeof(was));
- for (int i = 0; i < m; i++) {
- if (!was[i]) {
- cur++;
- dfs2(i);
- }
- }
- cout << mx + 1 << " " << cur << endl;
- for (int i = 0; i < mx; i++) {
- cerr << suf[mx][i] << endl;
- // return 0;
- cout << color[ suf[mx][i] ] << " ";
- }
- cout << endl;
- for (int i = 0; i < m; i++)
- cout << color[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement