本文整理汇总了C++中vvii::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ vvii::assign方法的具体用法?C++ vvii::assign怎么用?C++ vvii::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vvii
的用法示例。
在下文中一共展示了vvii::assign方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char const *argv[])
{
int n,m,u,v,t,s,r;
scanf("%d",&t);
while(t--){
for (int i = 0; i < 4000; ++i)
{
dist[i]= 500000;
}
memset(visited,0,sizeof(visited));
scanf("%d%d",&n,&m);
adjList.assign(n+1, vii());
for (int i = 0; i < m; ++i)
{
scanf("%d%d%d",&u,&v,&r);
adjList[u].push_back(ii(v,r));
adjList[v].push_back(ii(u,r));
}
scanf("%d",&s);
dijkastra(s);
for (int i = 1; i <= n; ++i)
{
if(i!=s&&dist[i]==500000)
printf("-1 ");
else if(i!=s)
printf("%d ", dist[i]);
}
printf("\n");
}
return 0;
}
示例2: main
int main() {
ios::sync_with_stdio(0);
int n;
while(cin >> n && n) {
graph.assign(n, vii());
for(int i = 0; i < n - 1; i ++) {
int a, b; cin >> a >> b;
a--, b--;
graph[a].push_back(ii(b, -1)), graph[b].push_back(ii(a, -1));
}
ways(n - 1, -1);
ways(0, -1);
vi dis(n, -1);
bfs(0, dis);
int l = 0, h = 3000, ans = 0;
while(l <= h) {
int mid = (l + h) / 2;
if(check(n - 1, -1, dis, mid)) h = mid - 1, ans = mid;
else l = mid + 1;
}
cout << ans << endl;
}
return 0;
}
示例3: main
int main() {
ios::sync_with_stdio(0);
int tc; cin >> tc;
while(tc--) {
int n; cin >> n;
fc.assign(n, pair<string, int>("", 0));
for(auto &e: fc) cin >> e.first >> e.first >> e.second;
n; cin >> n;
sc.assign(n, pair<string, int>("", 0));
for(auto &e: sc) cin >> e.first >> e.first >> e.second;
memo.assign(fc.size() + 10, vii(sc.size() + 10, ii(-1, -1)));
ii ans = solve(0, 0);
if(ans.first == inf && ans.second == inf) cout << 0 << " " << 0 << endl;
else cout << ans.first << " " << ans.second << endl;
}
return 0;
}
示例4: 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;
}
示例5: main
int main() {
ios::sync_with_stdio(0);
int n;
while(cin >> n && n) {
int m; cin >> m;
AdjList.assign(n + 10, vii());
for(int i = 0; i < m; i++) {
int a, b, c; cin >> a >> b >> c;
AdjList[a].push_back(ii(b, c));
AdjList[b].push_back(ii(a, c));
}
int s = 2;
dist.assign(n + 10, inf); dist[s] = 0;
priority_queue<ii, vector<ii>, greater<ii> > pq;
pq.push(ii(0, s));
while (!pq.empty()) {
ii front = pq.top(); pq.pop();
int d = front.first, u = front.second;
if (d > dist[u]) continue; // this is a very important check
for (int j = 0; j < (int) AdjList[u].size(); j++) {
ii v = AdjList[u][j];
if (dist[u] + v.second < dist[v.first]) {
dist[v.first] = dist[u] + v.second;
pq.push(ii(dist[v.first], v.first));
}
}
}
memo.assign(n + 10, -1);
cout << solve(1) << endl;
}
return 0;
}
示例6: main
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
while(cin >> n) {
if(n == -1) return 0;
adj2.assign(n, vi());
energy.assign(n, 0);
int k;
memset(mp, 0, sizeof(mp));
for(int i = 0; i < n; ++i) {
cin >> energy[i] >> k;
adj2[i].assign(k, 0);
for(int j = 0; j < k; ++j) {
cin >> adj2[i][j];
--adj2[i][j];
mp[i][adj2[i][j]] = 1;
}
}
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
mp[i][j] |= mp[i][k] & mp[k][j];
adj.assign(n, vii());
for(int i = 0; i < n; ++i) {
for(int j = 0; j < (int)adj2[i].sz(); ++j) {
adj[i].pb(ii(adj2[i][j], -energy[adj2[i][j]]));
}
}
dist.assign(n, INF);
dist[0] = -100;
for(int i = 0; i < n - 1; ++i)
for(int u = 0; u < n; ++u)
for(int j = 0; j < (int) adj[u].sz(); ++j) {
ii v = adj[u][j];
if(dist[u] + v.second < 0) {
dist[v.first] = min(dist[v.first], dist[u] + v.second);
}
}
if(dist[n - 1] < 0) cout << "winnable\n";
else {
bool hasNeg = false;
for(int u = 0; u < n; ++u) {
if(mp[u][n - 1]) {
for(int j = 0; j < (int) adj[u].sz(); ++j) {
ii v = adj[u][j];
if(dist[u] + v.second < 0 && dist[v.first] > dist[u] + v.second) {
hasNeg = true;
}
}
}
}
if(hasNeg) cout << "winnable\n";
else cout << "hopeless\n";
}
}
}