本文整理汇总了C++中vvi::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ vvi::assign方法的具体用法?C++ vvi::assign怎么用?C++ vvi::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vvi
的用法示例。
在下文中一共展示了vvi::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
ios::sync_with_stdio(0);
int tc; cin >> tc;
for(int i = 1; i <= tc; i++) {
cout << "Case #" << i << ": ";
int m; cin >> n >> m >> k;
graph.assign(n, vi(n, inf)), works.assign(k, ii(0, 0));
for(int i = 0; i < n; i++) graph[i][i] = 0;
for(int i = 0; i < m; i++) {
ll a, b, c; cin >> a >> b >> c;
a--, b--;
graph[a][b] = graph[b][a] = min(graph[a][b], c);
}
for(int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
works[i].first = a - 1, works[i].second = b - 1;
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
memo.assign(k + 1, vi(n + 1, -1));
int ans = solve(0, works[0].first) + graph[0][works[0].first];
if(ans >= inf) cout << -1 << endl;
else cout << ans << endl;
}
return 0;
}
示例2: e
CentroidDecomposition(vvi &tree) : e(tree) {
int V = e.size();
tocheck.assign(V, true);
cd.assign(V, vi());
dir.assign(V, vi());
p.assign(V, -1);
size.assign(V, 0);
dfs(0);
root = decompose(0, V);
}
示例3: main
int main(){
int n,m;
while(cin >> n){
int u, v; char c;
adj.assign(n,vi());
for(int i=0 ; i<n ; i++){
cin >> u; u--; cin.get();
while(cin.peek()!='\n'){
cin >> v; adj[u].push_back(v-1);
if(cin.get()=='\n') break;
}
}
int m; cin >> m;
cout << "-----" << endl;
while(m--){
int s, g;
cin >> s >> g; s--, g--;
vis.assign(n,-1);
par.assign(n,-1);
queue<int> q; q.push(s); vis[s]=0;
while(!q.empty()){
int u = q.front(); q.pop();
if( u == g ) break;
for(int i=0 ; i<adj[u].size() ; i++){
int v = adj[u][i];
if( vis[v]==-1 ){
q.push(v), vis[v]=vis[u]+1; par[v]=u;
}
}
}
if(par[g]==-1) cout << "connection impossible" << endl;
if(par[g]!=-1) printPath(g), cout << endl;
}
}
}
示例4: main
int main()
{
string u, v;
AdjList.assign(100005, vi());
ios_base :: sync_with_stdio(0); cin.tie(0);
int p1, p2;
int vertices = 0;
while (cin >> u >> v)
{
if (!m.count(u))
{
p1 = vertices;
m[u] = vertices++;
}
else p1 = m[u];
if (!m.count(v))
{
p2 = vertices;
m[v] = vertices++;
}
else p2 = m[v];
AdjList[p1].push_back(p2);
}
dfs_num.assign(vertices, UNVISITED); dfs_low.assign(vertices, 0); visited.assign(vertices, 0);
dfsNumberCounter = numSCC = 0;
for (int i = 0; i < vertices; i++)
if (dfs_num[i] == UNVISITED)
tarjanSCC(i);
cout << numSCC << '\n';
}
示例5: dijkstra_multiple_paths
void dijkstra_multiple_paths(vvii& g, int src, vi& dist, vvi& pred) {
// initialize
dist.assign(g.size(), numeric_limits<int>::max());
dist[src] = 0;
pred.assign(g.size(), vector<int>());
set<ii> set = { { 0, src } };
while (!set.empty()) {
// extract min
int u = set.begin()->second;
set.erase(set.begin());
for (auto& e : g[u]) {
int v = e.first;
int w = e.second;
if (dist[u] + w < dist[v]) {
// relax / decrease key
set.erase({ dist[v], v });
dist[v] = dist[u] + w;
pred[v] = { u };
set.insert({ dist[v], v });
} else if(dist[u] + w == dist[v]) {
pred[v].push_back(u);
}
}
}
}
示例6: main
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//Scanner sc;
//int cases = sc.nextInt();;
int cases;
cin >> cases;
while (cases--) {
//n = sc.nextInt();
cin >> n;
//set<pair<int,int> > e1, e2;
vvi t1(n);
for (int i = 0; i < n - 1; i++) {
//int a=sc.nextInt();
//int b=sc.nextInt();
int a, b;
scanf("%d%d", &a, &b);
--a, --b;
t1[a].push_back(b);
t1[b].push_back(a);
//e1.insert(make_pair(a, b));
}
vvi t2(n);
for (int i = 0; i < n - 1; i++) {
//int a=sc.nextInt();
//int b=sc.nextInt();
int a, b;
scanf("%d%d", &a, &b);
--a, --b;
t2[a].push_back(b);
t2[b].push_back(a);
//e2.insert(make_pair(a, b));
}
tree.assign(2 * n, vi());
for (int u = 0; u < n; u++) {
for (int i = 0; i < t1[u].size(); i++) {
int v = t1[u][i];
tree[u].push_back(v);
}
for (int i = 0; i < t2[u].size(); i++) {
int v = t2[u][i];
tree[u + n].push_back(v + n);
}
}
bool res = treeIsomorphism();
cout << (res ? "YES" : "NO") << endl;
}
}
示例7: rootedTreeIsomorphism
bool rootedTreeIsomorphism(int r1, int r2) {
L.assign(n, vi());
pred.assign(2 * n, -1);
children.assign(2 * n, vi());
int h1 = dfs(r1);
int h2 = dfs(r2);
if (h1 != h2)
return false;
int h = h1 - 1;
vi label(2 * n);
subtreeLabels.assign(2 * n, vi());
for (int i = h - 1; i >= 0; i--) {
for (int j = 0; j < (int) L[i + 1].size(); j++) {
int v = L[i + 1][j];
subtreeLabels[pred[v]].push_back(label[v]);
}
/*for (int j = 0; j < (int) L[i].size(); j++) {
int v = L[i][j];
sort(subtreeLabels[v].begin(), subtreeLabels[v].end());
}*/
sort(L[i].begin(), L[i].end(), compare);
for (int j = 0, cnt = 0; j < (int) L[i].size(); j++) {
if (j && !equals(L[i][j], L[i][j - 1]))
++cnt;
label[L[i][j]] = cnt;
}
}
if (!equals(r1, r2))
return false;
//generateMapping(r1, r2);
return true;
}
示例8: aho_corasick
void aho_corasick(string &sentence, vector<string> &words,vvi &matches){
matches.assign(sentence.length(), vi());
int state = 0, ss = 0;
for (int i = 0; i < sentence.length(); ++i, ss = state) {
while (a[ss].child[mp(sentence[i])] == -1)
ss = a[ss].failure;
state = a[state].child[mp(sentence[i])]
= a[ss].child[mp(sentence[i])];
for (ss = state; ss != -1; ss = a[ss].match_par)
for (int w : a[ss].match)
matches[i + 1 - words[w].length()].push_back(w);
}
}
示例9: main
int main()
{
freopen("input.txt", "r", stdin);
int n, t;
cin >> n;
g.assign(n, vi(0));
// read graph
for (int i = 0; i < n; ++i) {
scanf("%d", &t);
g[i].assign(t, 0);
for (int j = 0; j < t; ++j) {
scanf("%d", &g[i][j]);
g[i][j]--;
}
}
// partitioning
group.assign(n, 0);
used.assign(n, false);
for (int i = 0; i < n; ++i) {
if (!used[i])
dfs(i, 0);
}
// output
int count = 0, gr = 0;
for (int i = 0; i < n; ++i)
if (group[i] == 0) count++;
if (count > n - count) gr = 1, count = n - count;
if (count == n - count) gr = group[0];
printf("%d\n", count);
for (int i = 0; i < n; ++i) {
if (group[i] == gr) {
printf("%d ", i + 1);
}
}
printf("\n");
return 0;
}
示例10: main
int main() {
int T;
cin >> T;
for (int c = 1; c <= T; c++) {
int b, n;
cin >> b >> n;
t = b+n+1;
adjList.assign(t+1, vi());
for (int i = 0; i <= t; i++)
for (int j = 0; j <= t; j++)
res[i][j] = 0;
for (int i = 1; i <= b; i++) {
res[s][i] = 1;
adjList[s].push_back(i);
adjList[i].push_back(s);
for (int j = 1; j <= n; j++) {
int x;
cin >> x;
res[i][b + j] = x;
if (x == 1) {
adjList[i].push_back(b + j);
adjList[b + j].push_back(i);
}
}
}
for (int j = 1; j <= n; j++) {
res[b + j][t] = 1;
adjList[b + j].push_back(t);
adjList[t].push_back(b + j);
}
int mf = edmondKarps(adjList);
printf("Case %d: a maximum of %d nuts and bolts can be fitted together\n", c, mf);
}
return 0;
}
示例11: main
int main() {
ios::sync_with_stdio(0);
int tc; cin >> tc;
while(tc--) {
scc.clear();
int n, m; cin >> n >> m;
AdjList.assign(n, vii());
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
a--, b--;
if(a != b)
AdjList[a].push_back(ii(b, 0));
}
int V = n;
dfs_num.assign(V, 0); dfs_low.assign(V, 0); visited.assign(V, 0); node_to_scc_num.assign(V, -1);
dfsNumberCounter = numSCC = scc_num = 0;
for (int i = 0; i < V; i++)
if (dfs_num[i] == 0)
tarjanSCC(i);
graph.assign(scc_num, vi());
for(int i = 0; i < scc.size(); i++) {
for(int j = 0; j < scc[i].size(); j++) for(auto &e: AdjList[scc[i][j]])
if(node_to_scc_num[e.first] != i) graph[i].push_back(node_to_scc_num[e.first]);
}
memo.assign(scc_num, -1);
int ans = 0;
for(int i = 0; i < scc_num; i++) {
int cur = scc[i].size();
ans = max(ans, solve(i) + cur);
}
cout << ans << endl;
}
return 0;
}
示例12: exist
bool exist(vector<vector<char>>& board, string word) {
all = board;
if(word == "" || board.size() == 0) return false;
rsz = board.size();
wsz = word.size();
if(rsz == 0) return false;
csz = board[0].size();
vi ttmp (csz,0);
mark.assign(rsz, ttmp);
int flag = 0;
for(int i = 0; i < rsz; i++) {
for(int j = 0; j < csz; j++) {
if(all[i][j] == word[0]) {
//cout << i << " " << j << endl;
mark[i][j] = 1;
flag |= rec(0, i, j, word);
mark[i][j] = 0;
if(flag) return true;
}
}
}
return false;
}
示例13: main
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
edge.assign(n, vi());
for (int C = 0; C < n - 1; ++C) {
int i, j;
cin >> i >> j;
i--; j--;
edge[i].push_back(j);
edge[j].push_back(i);
}
f1.assign(n, -1);
f2.assign(n, -1);
if (n == 2) {
cout << "1 2\n1 2" << endl;
}
else {
int u = 0;
for (int i = 0; i < n; ++i) if (edge[i].size() == 1) u = i;
c = 2;
dfs(u, 1);
for (int i = 0; i < n; ++i) {
cout << f1[i] << ' ' << f2[i] << '\n';
}
cout << endl;
}
return 0;
}
示例14: main
int main()
{
// freopen("input.txt", "r", stdin);
int n;
cin >> n;
g.assign(n, vi());
used.assign(n, false);
values.assign(n, 0);
int t, v;
cin >> t;
values[0] = t;
for (int i = 1; i < n; ++i) {
cin >> t >> v;
g[t - 1].push_back(i);
values[i] = v;
}
// for (size_t i = 0; i < g.size(); ++i) {
// cout << i << "(" << values[i] << "): ";
// for (size_t j = 0; j < g[i].size(); ++j) {
// cout << g[i][j] << " (" << values[g[i][j]] << ") ";
// }
// cout << endl;
// }
//
// for (size_t i = 0; i < values.size(); ++i) {
// cout << values[i] << " ";
// }
// cout << endl;
dfs(0);
cout << values[0] << endl;
return 0;
}
示例15: main
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
dist.reserve(505);
while(scanf("%d %d %d", &n, &m, &q) != EOF)
{
for (int i = 0 ; i < n ;i++)
{
scanf("%d", &idade[i]);
}
v.assign(n, vi());
for (int i = 0 ; i < m; i++)
{
scanf("%d %d", &s, &d);
--s; --d;
v[d].push_back(s);
}
for (int i = 0 ; i < q; i++)
{
getchar();
scanf("%c %d", &c, &s);
--s;
if (c == 'P')
{
queue<int> q;
dist.clear();
for (int i = 0 ; i < n ; i++) dist[i] = INF;
dist[s] = 0;
q.push(s);
int mn = INF;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i = 0 ; i < v[u].size(); i++)
{
int aux = v[u][i];
if (dist[aux] > dist[u] + 1)
{
dist[aux] = dist[u] + 1;
mn = min(mn, idade[aux]);
q.push(aux);
}
}
}
if (mn == INF) printf("*\n");
else printf("%d\n", mn);
}
else
{
scanf("%d", &d);
--d;
for (int i = 0 ; i < n; i++)
{
for (int j = 0; j < v[i].size(); j++)
{
if (v[i][j] == s)
v[i][j] = d;
else if (v[i][j] == d)
v[i][j] = s;
}
}
vi aux = v[s];
v[s] = v[d];
v[d] = aux;
}
}
v.clear();
}
}