cf909e E. Coprocessor

本文介绍了一种使用两个队列实现的拓扑排序算法,该算法通过维护入度数组和两个队列来处理有向无环图的顶点排序问题。适用于需要对任务依赖关系进行排序的场景。

两个队列的拓扑排序

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>

using namespace std;

int n,m;
int e[100005];

vector<int> vec[100005];
int in[100005];

int main() {
    while(~scanf("%d%d",&n,&m))
    {
        memset(in,0,sizeof(in));
        for(int i=0;i<=100000;i++)
            vec[i].clear();

        for(int i=0;i<n;i++)
        {
            scanf("%d",&e[i]);
        }
        for(int i=0;i<m;i++)
        {
            int t1,t2;
            scanf("%d%d",&t1,&t2);
            vec[t2].push_back(t1);
            in[t1]++;
        }

        queue<int> q1,q2;
        for(int i=0;i<n;i++)
        {
            if(in[i]==0)
            {
                if(e[i]==0)
                {
                    q1.push(i);
                } else
                {
                    q2.push(i);
                }
            }
        }

        int ans=0;
        while(!(q1.empty() && q2.empty()))
        {
            while(!q1.empty())
            {
                int cur=q1.front();
                q1.pop();
                int len=vec[cur].size();
                for(int i=0;i<len;i++)
                {
                    int v=vec[cur][i];
                    in[v]--;
                    if(in[v]==0)
                    {
                        if(e[v]==0)
                            q1.push(v);
                        else
                            q2.push(v);
                    }
                }
            }

            if(!q2.empty())
                ans++;
            while(!q2.empty())
            {
                int cur=q2.front();
                q2.pop();
                int len=vec[cur].size();

                for(int i=0;i<len;i++)
                {
                    int v=vec[cur][i];
                    in[v]--;
                    if(in[v]==0)
                    {
                        if(e[v]==0)
                            q1.push(v);
                        else
                            q2.push(v);
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

WindowManager: Apply window transaction, syncId=-1 行 123519: 10-28 16:30:53.492 01723 04101 V WindowManager: Sending position change to ActivityRecord{732b4c8 u0 com.oplus.camera/.Camera t22}, onTop: false 行 123520: 10-28 16:30:53.492 01723 04101 V WindowManager: Waiting for top state to be released by ActivityRecord{732b4c8 u0 com.oplus.camera/.Camera t22} 行 123635: 10-28 16:30:53.527 01723 04101 V WindowManager: setClientVisible: ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} clientVisible=true Callers=com.android.server.wm.ActivityRecord.setClientVisible:8954 com.android.server.wm.ActivityRecord.setVisibility:6903 com.android.server.wm.ActivityRecord.s … 行 123636: 10-28 16:30:53.527 01723 04101 D WindowManager: NFW_setClientVisible:ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} clientVisible:true 行 123639: 10-28 16:30:53.528 01723 04101 V WindowManager: No longer Stopped: ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} 行 123641: 10-28 16:30:53.528 01723 04101 V WindowManager: Moving to RESUMED: ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} (in existing) 行 123642: 10-28 16:30:53.528 01723 04101 V WindowManager: State movement: ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} from:STOPPED to:RESUMED reason:resumeTopActivity 行 123687: 10-28 16:30:53.538 01723 04101 D WindowManager: updateOrientation: mLastOrientation = SCREEN_ORIENTATION_SENSOR(4) newOrientation = SCREEN_ORIENTATION_NOSENSOR(5) forceUpdate = true LastOrientationSource = ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} 行 123688: 10-28 16:30:53.538 01723 04101 D WindowManager: rotation(ROTATION_0) no changed displayId = 0, lastOrientation = 5 行 123691: 10-28 16:30:53.539 01723 04101 V WindowManager: notifyAppResumed: wasStopped=false ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6} 行 123822: 10-28 16:30:53.563 01723 04101 D WindowManager: resumeTopActivity: Resumed ActivityRecord{2ce909e u0 com.android.launcher/.Launcher t6}, caller com.android.server.wm.ActivityStartController.startExistingRecents:641 com.android.server.wm.ActivityStartController.startExistingRecentsIfPossible:602 com.android … 行 123833: 10-28 16:30:53.573 01723 04101 V WindowManager: commitVisibility: WallpaperWindowToken{6193035 token=android.os.Binder@89ddbc9 showWhenLocked=false}: visible=false mVisibleRequested=true 行 123834: 10-28 16:30:53.574 01723 04101 V WindowManager: setClientVisible: WallpaperWindowToken{6193035 token=android.os.Binder@89ddbc9 showWhenLocked=false} clientVisible=true Callers=com.android.server.wm.WallpaperWindowToken.setVisible:212 com.android.server.wm.WallpaperWindowToken.commitVisibility:271 com.andro … 行 123835: 10-28 16:30:53.574 01723 04101 D WindowManager: NFW_setClientVisible:WallpaperWindowToken{6193035 token=android.os.Binder@89ddbc9 showWhenLocked=false} clientVisible:true 行 123910: 10-28 16:30:53.584 01723 04101 D OplusZoomWindowManagerService: saveSupportFreeFormToTaskInfo target = com.oplus.camera/.Camera isSupportZoomMode = false 行 123996: 10-28 16:30:53.591 03776 13997 V WindowManagerShell: onTransitionReady(transaction=7400228713447) 行 124029: 10-28 16:30:53.599 01723 04101 V WindowManager: Task info changed taskId=1 行 124031: 10-28 16:30:53.599 01723 04101 D FlexibleWindowManagerService: onFlexibleWindowTaskInfoChanged: mTaskId = 1 oldIsTaskEmbedded = false curIsTaskEmbedded = false topActivity = ComponentInfo{com.android.launcher/com.android.launcher.Launcher} taskVisible = true 行 124038: 10-28 16:30:53.600 01723 04101 E FlexibleWindowManagerService: notifyTaskObserverToAttachController not need to notify! 行 124039: 10-28 16:30:53.600 01723 04101 I FlexibleWindowManagerService: onFlexibleWindowTaskInfoChanged, return for cur task not embedded 行 124185: 10-28 16:30:53.624 01723 04101 W WindowManager: captureTaskSnapshot mSnapshotMode= 0 source=Task{48d947 #22 type=standard A=10177:com.oplus.camera} 逐句解析日志,是从相机可见到桌面可见吗?
10-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值