Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<map>
- #include<vector>
- #include<stack>
- #include<algorithm>
- #include<cmath>
- #include<set>
- #include<iomanip>
- #include<fstream>
- using namespace std;
- int t = 0;
- void dfs (vector<set<int>> &g, vector<bool> &used, vector<int> &tin, int v, bool &p) {
- used[v] = true;
- tin[v] = t++;
- for(auto u = g[v].begin(); u != g[v].end(); u++) {
- cout << v << ' ' << used.size() << ' ' << *u << endl;
- if(!used[*u])
- dfs(g, used, tin, *u, p);
- p = false;
- }
- }
- int main() {
- ifstream in("fortification.in");
- ofstream out("fortification.out");
- int n;
- cin >> n;
- vector<string> inp(n);
- for(int i = 0; i < n; i++) {
- cin >> inp[i];
- string s = "";
- for(int j = 0; j < 10 - inp[i].length() + 1; j++)
- s += 'x';
- s += inp[i];
- inp[i] = s;
- }
- vector<set<int>> g(10);
- for(int i = 0; i < n; i++) {
- for(int j = i + 1; j < n; j++) {
- int c = 0;
- while(c < 10 && inp[i][c] == inp[j][c])
- c++;
- if(c < 11) {
- g[inp[j][c] - 'a'].insert(inp[i][c] - 'a');
- }
- }
- }
- vector<bool> used(10, false);
- vector<int> tin(10);
- bool p = true;
- for(int i = 0; i < 10; i++) {
- if(!used[i]) {
- dfs(g, used, tin, i, p);
- }
- }
- if(p) {
- cout << "Yes" << endl;
- for(int k : tin)
- cout << k << ' ';
- cout << endl;
- }
- else
- cout << "No" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement