AcWing 3239. 权限查询
原题链接
中等
作者:
鲶鱼饭
,
2022-08-17 14:39:26
,
所有人可见
,
阅读 218
#include <iostream>
#include <vector>
#include <unordered_map>
#define x first
#define y second
using namespace std;
typedef pair<string , int> PSI;
unordered_map<string , int> m1;
unordered_map<string , unordered_map<string , int>> m2;
unordered_map<string , vector<string>> m3;
pair<string , int> change(string s1){
string s = "";
int p = 0;
while(p < s1.size() && s1[p] != ':') s += s1[p ++];
if(p == s1.size()) return {s , -1};
else return {s , s1[p + 1] - 48};
}
int main(){
int p , r , u , q;
cin >> p;
while(p -- ){
string s1;
cin >> s1;
PSI t = change(s1);
m1[t.x] = t.y;
}
cin >> r;
while(r -- ){
string s1 , s2;
int n;
cin >> s1 >> n;
unordered_map<string , int> m;
for(int i = 0; i < n; i ++ ){
cin >> s2;
PSI t = change(s2);
if(m.count(t.x)){
if(t.y > m[t.x]) m[t.x] = t.y;
} else {
m[t.x] = t.y;
}
}
m2[s1] = m;
}
cin >> u;
while(u --){
string s1 , s2;
int n;
vector<string> vec;
cin >> s1 >> n;
while(n -- ){
cin >> s2;
vec.push_back(s2);
}
m3[s1] = vec;
}
cin >> q;
while(q -- ){
string s1 , s2;
cin >> s1 >> s2;
PSI t = change(s2);
if(!m3.count(s1)){
cout << "false" << endl;
continue;
}
vector<string> vec = m3[s1];
bool flag = true;
int ans = -100;
for(string s4 : vec){
if(m2[s4].count(t.x)){
if(m2[s4][t.x] >= t.y){
if(ans < m2[s4][t.x]) ans = m2[s4][t.x];
flag = false;
}
}
}
if(!flag){
if(t.y == -1 && ans != -1){
cout << ans << endl;
} else {
cout << "true" << endl;
}
} else {
cout << "false" << endl;
}
}
}