本文整理汇总了C++中graph::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::assign方法的具体用法?C++ graph::assign怎么用?C++ graph::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::assign方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
int test; cin >> test;
int a = 1;
while(test--) {
cin >> r >> c >> m >> n >> w;
g.assign(r, vector<int>(c,0));
visited.assign(r, vector<int>(c,0));
for(int i = 0; i < w; i++) {
int x, y; cin >> x >> y;
g[x][y] = -1;
}
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
if(g[i][j] != -1)
g[i][j] = connectedFields(i,j).size();
}
}
even = 0; odd = 0;
bfs();
cout << "Case " << a << ": " << even << " " << odd << endl;
a++;
}
}
示例2: main
int main() {
int N; cin >> N;
col.resize(N);
g.assign(N,vector<int>());
for(int i = 0; i < N; ++i) cin >> col[i];
for(int i = 0; i < N-1; ++i) {
int u,v; cin >> u >> v;
u--; v--;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(-1,0,0);
dfs(-1,max_v,1);
cout << max_dist/2 << endl;
return 0;
}
示例3: main
int main()
{
//freopen("testL.txt","r",stdin);
ios_base::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
DP.clear();
int k;
cin>>k;
int n;
cin>>n;
G.assign(n,list<road>());
int r;
cin>>r;
while(r--)
{
int a,b,l,t;
cin>>a>>b>>l>>t;
a--;
b--;
G[a].push_back(road(b,l,t));
}
int ans=solve(0,k);
if(ans>=INVALID)
cout<<-1<<endl;
else
cout<<ans<<endl;
}
}
示例4: main
int main() {
while(cin >> N >> M) {
if(N == 0 && M == 0) break;
euler.clear();
g.assign(N,vector<int>()); in.assign(N,0); out.assign(N,0);
for(int i = 0; i < M; ++i) {
int u, v; cin >> u >> v;
g[u].push_back(v);
out[u]++; in[v]++;
}
int cnt = 0;
vector<int> start(2,-1);
for(int i = 0; i < N; ++i) {
if(in[i] != out[i]) {
if(cnt < 2) start[cnt] = i;
cnt++;
}
}
if(cnt == 0) {
int s = 0;
for(; s < N; ++s) {
if(g[s].size() > 0) break;
}
eulerTour(s);
} else if(cnt == 1) {
int u = start[0];
if(out[u] == in[u]+1) eulerTour(u);
else {
cout << "Impossible" << endl;
continue;
}
} else if(cnt == 2) {
int u = start[0], v = start[1];
if(out[u] == in[u]+1 && in[v] == out[v] +1) {
int s = u; eulerTour(s);
} else if(out[v] == in[v]+1 && in[u] == out[u] +1) {
int s = v; eulerTour(s);
}
else {
cout << "Impossible" << endl;
continue;
}
} else {
cout << "Impossible" << endl;
continue;
}
reverse(euler.begin(),euler.end());
if(euler.size() != M+1) {
cout << "Impossible" << endl;
continue;
}
for(int i = 0; i < euler.size(); ++i) cout << euler[i] << (i == euler.size()-1 ? "\n" : " ");
}
return 0;
}